Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ktor integration - models allowed?

See original GitHub issue

Hi, trying to use jte with ktor ( however the example and the JteContent function appears to only accept a map of params, rather than any models or objects.

The example code is

get("/index") {
    // ktor example (no model, just a map of params)
      val params = mapOf("id" to 1, "name" to "John")
      call.respond(JteContent("index.kte", params))
    // my attempt, using a model - type mismatch
      call.respond(JteContent("test.kte", MyModel(id = 1, name = "John")))

// my attempt requires a data class (but fails anyway)
data class MyModel(val id: Int, val name: String)

This would seem to limit compatibility with jte templates that expect models, plus make creating new templates more tedious. Am I missing a way to use models with Ktor and jte or is it limited to Maps/Params? Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2x2xplzcommented, Jul 8, 2022

Oh, I’m not sure how ktor’s development mode is implemented, but my guess would be that they use a custom ClassLoader for this. There’s been a similiar issue with spring boot, so that might be a good starting point: #70 (comment)

Just to be clear, this is not a bug or a problem with jte. Just wanted to document the fix in case someone has the same issue and does a search for ClassCastException or something similar.

casidcommented, Jul 8, 2022

I just released version 2.1.2 to maven central, including this fix 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating HTTP APIs - Ktor
In this tutorial, we're going to create an HTTP API that can serve as a backend for any application, be it mobile, web,...
Read more >
Application structure | Ktor
NET MVC or Ruby on Rails, have the concept of structuring applications using three folders - Model, View, and Controllers (Routes).
Read more >
Database persistence with Exposed - Ktor
package com.example.models import ... Ktor allows you to extract such settings to a custom configuration group.
Read more >
Creating a cross-platform mobile application - Ktor
In this tutorial, we'll create a simple Kotlin Multiplatform Mobile application, which sends a request and receives a response body as plain HTML...
Read more >
Creating an interactive website - Ktor
First, we need to create a model describing an article in our journal application. Create a models package inside com.example , add the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found