Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

[SOLVED] @JsonProperty Unsuccessfully trying to parse the PascalCase.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My task is to get a callback from an ASP.NET application which uses PascalCase, not fooBar -> FooBar unlike Java. I am using the model below where @JsonProperty is logically used, but unfortunately I don't see the effect, I can only see the result of serialization if I send camelCase. Why this annotation doesn't work?



  • JDK 1.8
  • Output for $ mvn dependency:tree -Dverbose - https://gist.githubusercontent.com/sergey-prosvirnin/694f630fb04a33d1cfe530715c7f9396/raw/4c59e1c46dd7bca161a1cee100b5ae91db614ee6/$%2520mvn%2520dependency:tree%2520-Dverbose
  •  
    Sheriff
    Posts: 22509
    122
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Are you sure that Jackson is being used here? I've worked with WebLogic, and that used MOXy out-of-the-box. I think that JBoss tries to use JSON-P by default. Maybe your server uses one of these, or something else.
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rob Spoor wrote:Are you sure that Jackson is being used here? I've worked with WebLogic, and that used MOXy out-of-the-box. I think that JBoss tries to use JSON-P by default. Maybe your server uses one of these, or something else.



    Yes, the rest of Jackson's annotations work great in this project, I use Tomcat.
     
    Saloon Keeper
    Posts: 13391
    295
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Why do you have annotations on both your fields and your getters/setters?
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Why do you have annotations on both your fields and your getters/setters?



    This is autogeneration of pugin jsonschema2pojo - https://github.com/joelittlejohn/jsonschema2pojo
     
    Marshal
    Posts: 3718
    530
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Can you share an example of the JSON representation which is not being deserialized correctly?
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ron McLeod wrote:Can you share an example of the JSON representation which is not being deserialized correctly?



    Unsuccess - HTTP Status 400


    Success
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 13391
    295
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think it just completely ignores your annotations and uses the default names derived from your getters and setters to populate the object. How do you know that the annotations works correctly in the rest of the project?
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:I think it just completely ignores your annotations and uses the default names derived from your getters and setters to populate the object. How do you know that the annotations works correctly in the rest of the project?



    For example such announcements work as expected.




     
    Ron McLeod
    Marshal
    Posts: 3718
    530
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Sergei Prosvirnin wrote:For example such announcements work as expected.


    Those annotations are used during serialization - your issue is during deserialization.
     
    Ron McLeod
    Marshal
    Posts: 3718
    530
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Likes 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I don't think there the problem is with your annotated DTO. I used it in a simple Quarkus (not Spring) based project, and the payload deserialized as expected.
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ron McLeod wrote:I don't think there the problem is with your annotated DTO. I used it in a simple Quarkus (not Spring) based project, and the payload deserialized as expected.




    Thank you for this test, I am flattered by your involvement. I found a solution in the form of using the old version of the package (funny, usually on the forums they advise to change to the new one).

     
    Ron McLeod
    Marshal
    Posts: 3718
    530
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Likes 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For your reference - I tested with version 2.12.1, which is only a few months behind the latest.

    Also, I noticed from your POM tree that you were using version 2.6.3 for jackson-databind, and version 2.9.8 for jackson-annotations and jackson-core.  The different versions may have not been compatible (databind has a dependency on both annotations and core).
     
    Rob Spoor
    Sheriff
    Posts: 22509
    122
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Sergei Prosvirnin wrote:I found a solution in the form of using the old version of the package (funny, usually on the forums they advise to change to the new one).


    That's Jackson 1.x which has been inactive for a long, long time. The latest release I could find on Maven Central is from 2013.

    Jackson is (unfortunately) known for vulnerabilities that are found quite often (at least partly because of its extensive feature set), so you definitely don't want to use a version that's almost 8 years old. As long as you monitor for these vulnerabilities and update as soon as one is found, you should be pretty safe.

    For monitoring I use Snyk.io (free account), but at work we use Jenkins with the OWASP dependency checker. There are probably other solutions as well.

    Ron McLeod wrote:Also, I noticed from your POM tree that you were using version 2.6.3 for jackson-databind, and version 2.9.8 for jackson-annotations and jackson-core.  The different versions may have not been compatible (databind has a dependency on both annotations and core).


    This could very well be the cause of the issue. Certain library sets rely on using compatible versions. For instance, all Jackson libraries should have the same version; all POI libraries should have the same version; all Quarkus libraries should have the same version. If you have different versions, the results can be unpredictable. I've seen quite a number of NoSuchMethodError and similar errors because of version mismatches. Your case could well be that, although you don't get errors, something else goes wrong.
     
    Sergei Prosvirnin
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rob Spoor wrote:

    Sergei Prosvirnin wrote:I found a solution in the form of using the old version of the package (funny, usually on the forums they advise to change to the new one).


    That's Jackson 1.x which has been inactive for a long, long time. The latest release I could find on Maven Central is from 2013.

    Jackson is (unfortunately) known for vulnerabilities that are found quite often (at least partly because of its extensive feature set), so you definitely don't want to use a version that's almost 8 years old. As long as you monitor for these vulnerabilities and update as soon as one is found, you should be pretty safe.

    For monitoring I use Snyk.io (free account), but at work we use Jenkins with the OWASP dependency checker. There are probably other solutions as well.

    Ron McLeod wrote:Also, I noticed from your POM tree that you were using version 2.6.3 for jackson-databind, and version 2.9.8 for jackson-annotations and jackson-core.  The different versions may have not been compatible (databind has a dependency on both annotations and core).


    This could very well be the cause of the issue. Certain library sets rely on using compatible versions. For instance, all Jackson libraries should have the same version; all POI libraries should have the same version; all Quarkus libraries should have the same version. If you have different versions, the results can be unpredictable. I've seen quite a number of NoSuchMethodError and similar errors because of version mismatches. Your case could well be that, although you don't get errors, something else goes wrong.



    This is a rather large and old project, and in this case it is now impossible to upgrade to a new version, even due to the broken code of colleagues. Thanks for the help!
     
    Rob Spoor
    Sheriff
    Posts: 22509
    122
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You're welcome.
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic