2 Replies Latest reply on May 13, 2014 8:18 AM by tole42

    [8.1.0.CR2] jackson.map.annotate.JsonSerialize suddenly not working

    tole42

      Hi,

       

      i just upgraded from 8.1.0.CR1 to 8.1.0.CR2 and now the json serialization is not working anymore.

       

      @JsonSerialize(using = ToStringSerializer.class)
      private Long id;
      

       

      with CR1 i got the following (expected) response:

      {"id":"3379823201516157409"}
      

       

      with CR2 i got the following (wrong) response:

      {"id": 3379823201516157409}
      

       

       

      i could not find any changes in the release notes or in the bug tracker which could be responsible. Any ideas?

        • 1. Re: [8.1.0.CR2] jackson.map.annotate.JsonSerialize suddenly not working
          ctomc

          Hey,

           

          We have yet to compile changes list for release notes.

           

          What you are seeing is most probably caused by switching default jackson provider to jackson2 (from jackson1)

          which was highly demanded change and in general works much better and faster + has lots of new features that applications can utilize.

           

          In any case, to me it looks like newer json response you get now is correct and old one was wrong, you are serializing Long object which doesn't have to be quoted as a string.

           

          Maybe just annotations are not applied properly, try upgrading compile dependency in your application to jackson2 it might fix the problem.

          • 2. Re: [8.1.0.CR2] jackson.map.annotate.JsonSerialize suddenly not working
            tole42

            thanks for your quick reply and leading me to the right track.

             

            I have to quote the Long as string. Otherwise my javascript is not able to parse the value (In JavaScript, all numbers are 64 bits floating point numbers).

             

            I changed my imports (and pom.xml) from

             

            import org.codehaus.jackson.map.annotate.JsonSerialize;
            import org.codehaus.jackson.map.ser.std.ToStringSerializer;
            
            

             

            to

             

            import com.fasterxml.jackson.databind.annotation.JsonSerialize;
            import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
            
            

             

             

            new pom.xml:

             

             <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-core</artifactId>
                        <version>${version.jackson-core}</version>
                        <scope>provided</scope>
                    </dependency>
            
            
                    <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-annotations</artifactId>
                        <version>${version.jackson-core-annotation}</version>
                        <scope>provided</scope>
                    </dependency>
            
            
                    <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
                        <version>${version.jackson-core-databind}</version>
                        <scope>provided</scope>
                    </dependency>
            

             

            now everything is working. thanks!

            1 of 1 people found this helpful