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.

Parsing error: Klaxon drops parameters when using @TypeFor

See original GitHub issue

I try to deserialize objects of classes that are derieved from the Sensor class:

@TypeFor(field = "type", adapter = SensorTypeAdapter::class)
abstract class Sensor(val type: Type) {
    enum class Type { T1, T2, Test }

A test subclass looks like this:

class Test(val prop: String) : Sensor(Type.Test) 

And the TypeAdapter like this:

import com.beust.klaxon.TypeAdapter
import kotlin.reflect.KClass

class SensorTypeAdapter : TypeAdapter<Sensor> {
    override fun classFor(type: Any): KClass<out Sensor> =
        when (Sensor.Type.valueOf(type as String)) {
            Sensor.Type.Test -> Test::class
            else -> throw IllegalArgumentException("Unknown sensor type $type")

When trying to parse this I get the exception com.beust.klaxon.KlaxonException: Unable to instantiate Test with parameters []. So it seems to me that Klaxon found out which type to use (Test) but ignores all other parameters that can be found in the json:

    "type": "Test",
    "prop": "String"

I start the parsing by using a File object:


When removing the prop property from the json and the Test class the deserialisation works. How do I get it work with properties in my derieved class?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

cbeustcommented, Feb 12, 2019

Great suggestion, @wolpl, I just added this badge to the README.

Sorry for the inconvenience!

wolplcommented, Feb 12, 2019

As the build.gradle file shows and I mentioned above I used Klaxon 5.0.1. The error disappears when using Klaxon 5.0.5. Still it should not have worked in the example project because version 5.0.1 is used there…

@cbeust Thanks for your support. It would have helped to reference the latest version in the project readme - I had to find it manually at As of now applying the instructions in the readme (including version 5.0.1 via gradle) makes it impossible to use the polymorphism features described in the readme.

Perhaps a badge is a convenient solution to always show the latest available version: Download

 [ ![Download]( ](
Read more comments on GitHub >

github_iconTop Results From Across the Web

What to do if your typeform isn't working - Help Center
What to do if your typeform isn't working · 1. Include your typeform URL. · 2. Make a screen recording of the issue...
Read more >
Salesforce integration: Troubleshooting, limitations, and other ...
Click the Typeform Forms tab and select Forms with Active Mappings from the List Views dropdown menu. Click each form in the list...
Read more >
Responses API - Typeform's APIs
The Responses API lets you access the data your typeforms collect — on demand and in JSON format — without setting up webhooks...
Read more >
Logic Map - Help Center - Typeform
Logic is a feature that helps responders follow the path most relevant to them while completing a typeform. With a Logic Map you...
Read more >
FAQs: Typeform and Google Analytics - Help Center
There are a few possible reasons for this: 1. Your respondents are looking at a typeform but not interacting with it - Google...
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