Jackson registerSubtypes not working in KotlinJackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonHow to use Jackson to deserialise an array of objectsHow to tell Jackson to ignore a field during serialization if its value is null?Jackson: using builder with nondefault constructorHow to prevent jackson instantiating new object in deserializationHow do you make Jackson use Kotlin default params for missing values?How to parse JSON in Kotlin?Jackson, deserialize class with private fields and arg-constructor without annotationsUse spring's objectmapper with kotlin fuel

Why are on-board computers allowed to change controls without notifying the pilots?

The plural of 'stomach"

Valid Badminton Score?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Can a monster with multiattack use this ability if they are missing a limb?

How can I replace every global instance of "x[2]" with "x_2"

Is the destination of a commercial flight important for the pilot?

How will losing mobility of one hand affect my career as a programmer?

Is it okay / does it make sense for another player to join a running game of Munchkin?

Is there an Impartial Brexit Deal comparison site?

Failed to fetch jessie backports repository

Why Were Madagascar and New Zealand Discovered So Late?

Personal Teleportation as a Weapon

Is there a problem with hiding "forgot password" until it's needed?

Have I saved too much for retirement so far?

voltage of sounds of mp3files

How to prove that the query oracle is unitary?

Can criminal fraud exist without damages?

Opposite of a diet

Your magic is very sketchy

HashMap containsKey() returns false although hashCode() and equals() are true

What would happen if the UK refused to take part in EU Parliamentary elections?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

How can I use the arrow sign in my bash prompt?



Jackson registerSubtypes not working in Kotlin


Jackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonHow to use Jackson to deserialise an array of objectsHow to tell Jackson to ignore a field during serialization if its value is null?Jackson: using builder with nondefault constructorHow to prevent jackson instantiating new object in deserializationHow do you make Jackson use Kotlin default params for missing values?How to parse JSON in Kotlin?Jackson, deserialize class with private fields and arg-constructor without annotationsUse spring's objectmapper with kotlin fuel













1















I was trying to use the registerSubtypes function from Jackson following this tutorial.



So I've converted this code into Kotlin like so:



interface Vehicle 
val name: String

class Car @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle
class Truck @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle

class Vehicles @JsonCreator constructor(@JsonProperty("vehicles") var vehicles: List<Vehicle>)

fun main()
val MAPPER = jacksonObjectMapper()
MAPPER.registerSubtypes(NamedType(Truck::class.java, "Truck"))
MAPPER.registerSubtypes(NamedType(Car::class.java, "Car"))

val vehicles = Vehicles(listOf(Car("Dodge"), Truck("Scania")))
val json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(vehicles)
println(json)



But the output result is the following:




"vehicles" : [
"name" : "Dodge"
,
"name" : "Scania"
]



It doesn't contain the "@type" field, so deserialization doesn't work.



Any idea how to fix it?



Jackson Kotlin version: 2.9.6










share|improve this question




























    1















    I was trying to use the registerSubtypes function from Jackson following this tutorial.



    So I've converted this code into Kotlin like so:



    interface Vehicle 
    val name: String

    class Car @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle
    class Truck @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle

    class Vehicles @JsonCreator constructor(@JsonProperty("vehicles") var vehicles: List<Vehicle>)

    fun main()
    val MAPPER = jacksonObjectMapper()
    MAPPER.registerSubtypes(NamedType(Truck::class.java, "Truck"))
    MAPPER.registerSubtypes(NamedType(Car::class.java, "Car"))

    val vehicles = Vehicles(listOf(Car("Dodge"), Truck("Scania")))
    val json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(vehicles)
    println(json)



    But the output result is the following:




    "vehicles" : [
    "name" : "Dodge"
    ,
    "name" : "Scania"
    ]



    It doesn't contain the "@type" field, so deserialization doesn't work.



    Any idea how to fix it?



    Jackson Kotlin version: 2.9.6










    share|improve this question


























      1












      1








      1








      I was trying to use the registerSubtypes function from Jackson following this tutorial.



      So I've converted this code into Kotlin like so:



      interface Vehicle 
      val name: String

      class Car @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle
      class Truck @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle

      class Vehicles @JsonCreator constructor(@JsonProperty("vehicles") var vehicles: List<Vehicle>)

      fun main()
      val MAPPER = jacksonObjectMapper()
      MAPPER.registerSubtypes(NamedType(Truck::class.java, "Truck"))
      MAPPER.registerSubtypes(NamedType(Car::class.java, "Car"))

      val vehicles = Vehicles(listOf(Car("Dodge"), Truck("Scania")))
      val json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(vehicles)
      println(json)



      But the output result is the following:




      "vehicles" : [
      "name" : "Dodge"
      ,
      "name" : "Scania"
      ]



      It doesn't contain the "@type" field, so deserialization doesn't work.



      Any idea how to fix it?



      Jackson Kotlin version: 2.9.6










      share|improve this question
















      I was trying to use the registerSubtypes function from Jackson following this tutorial.



      So I've converted this code into Kotlin like so:



      interface Vehicle 
      val name: String

      class Car @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle
      class Truck @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle

      class Vehicles @JsonCreator constructor(@JsonProperty("vehicles") var vehicles: List<Vehicle>)

      fun main()
      val MAPPER = jacksonObjectMapper()
      MAPPER.registerSubtypes(NamedType(Truck::class.java, "Truck"))
      MAPPER.registerSubtypes(NamedType(Car::class.java, "Car"))

      val vehicles = Vehicles(listOf(Car("Dodge"), Truck("Scania")))
      val json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(vehicles)
      println(json)



      But the output result is the following:




      "vehicles" : [
      "name" : "Dodge"
      ,
      "name" : "Scania"
      ]



      It doesn't contain the "@type" field, so deserialization doesn't work.



      Any idea how to fix it?



      Jackson Kotlin version: 2.9.6







      json kotlin jackson jackson2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 22:15









      Michał Ziober

      16.8k1269108




      16.8k1269108










      asked Mar 7 at 16:58









      Benoit THBenoit TH

      1475




      1475






















          2 Answers
          2






          active

          oldest

          votes


















          1














          It is not related with Kotlin. Linked article uses Jackson in version 2.9.3. But a little bit later Another two gadgets to exploit default typing issue in jackson-databind (CVE-2018-5968) bug appeared and Jackson had to fixed that. In Jackson Release 2.9.4 this bug was fixed. Later on, new bug was created: Two morec3p0gadgets to exploit default typing issue [CVE-2018-7489] which was fixed in version 2.9.5. You are using version 2.9.6 and you noticed that behaviour changed a little bit since version 2.9.3. What does it mean for you? You need to enable default typing explicitly because it is not secure. This way:



          MAPPER.enableDefaultTyping()


          Check documentation to this method:




          NOTE: use of Default Typing can be a potential security risk if
          incoming content comes from untrusted sources, and it is recommended
          that this is either not done, or, if enabled, use setDefaultTyping passing a
          custom TypeResolverBuilder implementation that white-lists legal types to use.




          I suggest to read Inheritance with Jackson article and use the latest version of Jackson which right now is 2.9.9. Read more about CVE in Jackson in On Jackson CVEs: Don’t Panic — Here is what you need to know article.






          share|improve this answer


















          • 1





            Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

            – Benoit TH
            Mar 8 at 9:31


















          0














          I've figured it out.



          In case anyone has this issue in the future, in this particular example the Vehicle class would need to be annotated with @JsonTypeInfo like so :



          @JsonTypeInfo(use = NAME, include = PROPERTY)
          interface Vehicle





          share|improve this answer























          • This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

            – Michał Ziober
            Mar 8 at 16:22











          • JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

            – Michał Ziober
            Mar 8 at 16:25











          • My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

            – Benoit TH
            Mar 9 at 20:49











          • Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

            – Benoit TH
            Mar 9 at 20:55






          • 1





            So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

            – Benoit TH
            Mar 10 at 13:54










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049171%2fjackson-registersubtypes-not-working-in-kotlin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          It is not related with Kotlin. Linked article uses Jackson in version 2.9.3. But a little bit later Another two gadgets to exploit default typing issue in jackson-databind (CVE-2018-5968) bug appeared and Jackson had to fixed that. In Jackson Release 2.9.4 this bug was fixed. Later on, new bug was created: Two morec3p0gadgets to exploit default typing issue [CVE-2018-7489] which was fixed in version 2.9.5. You are using version 2.9.6 and you noticed that behaviour changed a little bit since version 2.9.3. What does it mean for you? You need to enable default typing explicitly because it is not secure. This way:



          MAPPER.enableDefaultTyping()


          Check documentation to this method:




          NOTE: use of Default Typing can be a potential security risk if
          incoming content comes from untrusted sources, and it is recommended
          that this is either not done, or, if enabled, use setDefaultTyping passing a
          custom TypeResolverBuilder implementation that white-lists legal types to use.




          I suggest to read Inheritance with Jackson article and use the latest version of Jackson which right now is 2.9.9. Read more about CVE in Jackson in On Jackson CVEs: Don’t Panic — Here is what you need to know article.






          share|improve this answer


















          • 1





            Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

            – Benoit TH
            Mar 8 at 9:31















          1














          It is not related with Kotlin. Linked article uses Jackson in version 2.9.3. But a little bit later Another two gadgets to exploit default typing issue in jackson-databind (CVE-2018-5968) bug appeared and Jackson had to fixed that. In Jackson Release 2.9.4 this bug was fixed. Later on, new bug was created: Two morec3p0gadgets to exploit default typing issue [CVE-2018-7489] which was fixed in version 2.9.5. You are using version 2.9.6 and you noticed that behaviour changed a little bit since version 2.9.3. What does it mean for you? You need to enable default typing explicitly because it is not secure. This way:



          MAPPER.enableDefaultTyping()


          Check documentation to this method:




          NOTE: use of Default Typing can be a potential security risk if
          incoming content comes from untrusted sources, and it is recommended
          that this is either not done, or, if enabled, use setDefaultTyping passing a
          custom TypeResolverBuilder implementation that white-lists legal types to use.




          I suggest to read Inheritance with Jackson article and use the latest version of Jackson which right now is 2.9.9. Read more about CVE in Jackson in On Jackson CVEs: Don’t Panic — Here is what you need to know article.






          share|improve this answer


















          • 1





            Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

            – Benoit TH
            Mar 8 at 9:31













          1












          1








          1







          It is not related with Kotlin. Linked article uses Jackson in version 2.9.3. But a little bit later Another two gadgets to exploit default typing issue in jackson-databind (CVE-2018-5968) bug appeared and Jackson had to fixed that. In Jackson Release 2.9.4 this bug was fixed. Later on, new bug was created: Two morec3p0gadgets to exploit default typing issue [CVE-2018-7489] which was fixed in version 2.9.5. You are using version 2.9.6 and you noticed that behaviour changed a little bit since version 2.9.3. What does it mean for you? You need to enable default typing explicitly because it is not secure. This way:



          MAPPER.enableDefaultTyping()


          Check documentation to this method:




          NOTE: use of Default Typing can be a potential security risk if
          incoming content comes from untrusted sources, and it is recommended
          that this is either not done, or, if enabled, use setDefaultTyping passing a
          custom TypeResolverBuilder implementation that white-lists legal types to use.




          I suggest to read Inheritance with Jackson article and use the latest version of Jackson which right now is 2.9.9. Read more about CVE in Jackson in On Jackson CVEs: Don’t Panic — Here is what you need to know article.






          share|improve this answer













          It is not related with Kotlin. Linked article uses Jackson in version 2.9.3. But a little bit later Another two gadgets to exploit default typing issue in jackson-databind (CVE-2018-5968) bug appeared and Jackson had to fixed that. In Jackson Release 2.9.4 this bug was fixed. Later on, new bug was created: Two morec3p0gadgets to exploit default typing issue [CVE-2018-7489] which was fixed in version 2.9.5. You are using version 2.9.6 and you noticed that behaviour changed a little bit since version 2.9.3. What does it mean for you? You need to enable default typing explicitly because it is not secure. This way:



          MAPPER.enableDefaultTyping()


          Check documentation to this method:




          NOTE: use of Default Typing can be a potential security risk if
          incoming content comes from untrusted sources, and it is recommended
          that this is either not done, or, if enabled, use setDefaultTyping passing a
          custom TypeResolverBuilder implementation that white-lists legal types to use.




          I suggest to read Inheritance with Jackson article and use the latest version of Jackson which right now is 2.9.9. Read more about CVE in Jackson in On Jackson CVEs: Don’t Panic — Here is what you need to know article.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 22:34









          Michał ZioberMichał Ziober

          16.8k1269108




          16.8k1269108







          • 1





            Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

            – Benoit TH
            Mar 8 at 9:31












          • 1





            Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

            – Benoit TH
            Mar 8 at 9:31







          1




          1





          Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

          – Benoit TH
          Mar 8 at 9:31





          Thanks very much for your help, I found the solution I'm going to put it here in a moment. It's not related to the version at all but thank you for pointing this out I'm going to update my dependencies.

          – Benoit TH
          Mar 8 at 9:31













          0














          I've figured it out.



          In case anyone has this issue in the future, in this particular example the Vehicle class would need to be annotated with @JsonTypeInfo like so :



          @JsonTypeInfo(use = NAME, include = PROPERTY)
          interface Vehicle





          share|improve this answer























          • This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

            – Michał Ziober
            Mar 8 at 16:22











          • JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

            – Michał Ziober
            Mar 8 at 16:25











          • My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

            – Benoit TH
            Mar 9 at 20:49











          • Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

            – Benoit TH
            Mar 9 at 20:55






          • 1





            So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

            – Benoit TH
            Mar 10 at 13:54















          0














          I've figured it out.



          In case anyone has this issue in the future, in this particular example the Vehicle class would need to be annotated with @JsonTypeInfo like so :



          @JsonTypeInfo(use = NAME, include = PROPERTY)
          interface Vehicle





          share|improve this answer























          • This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

            – Michał Ziober
            Mar 8 at 16:22











          • JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

            – Michał Ziober
            Mar 8 at 16:25











          • My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

            – Benoit TH
            Mar 9 at 20:49











          • Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

            – Benoit TH
            Mar 9 at 20:55






          • 1





            So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

            – Benoit TH
            Mar 10 at 13:54













          0












          0








          0







          I've figured it out.



          In case anyone has this issue in the future, in this particular example the Vehicle class would need to be annotated with @JsonTypeInfo like so :



          @JsonTypeInfo(use = NAME, include = PROPERTY)
          interface Vehicle





          share|improve this answer













          I've figured it out.



          In case anyone has this issue in the future, in this particular example the Vehicle class would need to be annotated with @JsonTypeInfo like so :



          @JsonTypeInfo(use = NAME, include = PROPERTY)
          interface Vehicle






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 9:34









          Benoit THBenoit TH

          1475




          1475












          • This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

            – Michał Ziober
            Mar 8 at 16:22











          • JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

            – Michał Ziober
            Mar 8 at 16:25











          • My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

            – Benoit TH
            Mar 9 at 20:49











          • Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

            – Benoit TH
            Mar 9 at 20:55






          • 1





            So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

            – Benoit TH
            Mar 10 at 13:54

















          • This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

            – Michał Ziober
            Mar 8 at 16:22











          • JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

            – Michał Ziober
            Mar 8 at 16:25











          • My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

            – Benoit TH
            Mar 9 at 20:49











          • Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

            – Benoit TH
            Mar 9 at 20:55






          • 1





            So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

            – Benoit TH
            Mar 10 at 13:54
















          This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

          – Michał Ziober
          Mar 8 at 16:22





          This annotation does the same what JsonSubTypes but with different attributes. We can provide some extra configuration using enableDefaultTyping or enableDefaultTyping(with params)

          – Michał Ziober
          Mar 8 at 16:22













          JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

          – Michał Ziober
          Mar 8 at 16:25





          JsonSubTypes annotation in documentation says: "Note that just annotating a property or base type with this annotation does NOT enable polymorphic type handling: in addition, JsonTypeInfo or equivalent (such as enabling of so-called "default typing") annotation is needed, and only in such case is subtype information used." Where so-called "default typing" is our enableDefaultTyping method on ObjectMapper. So we have two ways to enable types: by method and annotation.

          – Michał Ziober
          Mar 8 at 16:25













          My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

          – Benoit TH
          Mar 9 at 20:49





          My point was if only registerSubtypes is used it doesn't work, I also needed to add the annotation

          – Benoit TH
          Mar 9 at 20:49













          Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

          – Benoit TH
          Mar 9 at 20:55





          Basically JsonTypeInfo registers the class for polymorphism so it is required when using registerSubtype and that's what my problem was

          – Benoit TH
          Mar 9 at 20:55




          1




          1





          So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

          – Benoit TH
          Mar 10 at 13:54





          So I tried using Java and I have the same issue, @JsonTypeInfo needs to be there no matter what. No idea why we're having different behaviours. At least it works for me now :) Thanks for your help anyway

          – Benoit TH
          Mar 10 at 13:54

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049171%2fjackson-registersubtypes-not-working-in-kotlin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229