Java 8 Exception: com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer has no default (no arg) constructor









up vote
0
down vote

favorite












I have a model class that has a field:



 @JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;


When a request of this model is sent to the server, my controller throws an exception:



Caused by: java.lang.IllegalArgumentException: 
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor


The pom.xml has the dependency of version 2.8.11:



 <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>


I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.










share|improve this question























  • InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
    – Deadpool
    Nov 9 at 20:08










  • @Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
    – jlp
    Nov 9 at 20:10











  • what does your POM look like?
    – Darren Forsythe
    Nov 9 at 20:15






  • 1




    Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
    – Julio Daniel Reyes
    Nov 9 at 21:31






  • 1




    For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
    – Julio Daniel Reyes
    Nov 9 at 21:35














up vote
0
down vote

favorite












I have a model class that has a field:



 @JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;


When a request of this model is sent to the server, my controller throws an exception:



Caused by: java.lang.IllegalArgumentException: 
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor


The pom.xml has the dependency of version 2.8.11:



 <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>


I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.










share|improve this question























  • InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
    – Deadpool
    Nov 9 at 20:08










  • @Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
    – jlp
    Nov 9 at 20:10











  • what does your POM look like?
    – Darren Forsythe
    Nov 9 at 20:15






  • 1




    Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
    – Julio Daniel Reyes
    Nov 9 at 21:31






  • 1




    For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
    – Julio Daniel Reyes
    Nov 9 at 21:35












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a model class that has a field:



 @JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;


When a request of this model is sent to the server, my controller throws an exception:



Caused by: java.lang.IllegalArgumentException: 
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor


The pom.xml has the dependency of version 2.8.11:



 <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>


I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.










share|improve this question















I have a model class that has a field:



 @JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;


When a request of this model is sent to the server, my controller throws an exception:



Caused by: java.lang.IllegalArgumentException: 
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor


The pom.xml has the dependency of version 2.8.11:



 <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>


I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.







java json jackson fasterxml jsr310






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 20:50

























asked Nov 9 at 20:03









jlp

4091822




4091822











  • InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
    – Deadpool
    Nov 9 at 20:08










  • @Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
    – jlp
    Nov 9 at 20:10











  • what does your POM look like?
    – Darren Forsythe
    Nov 9 at 20:15






  • 1




    Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
    – Julio Daniel Reyes
    Nov 9 at 21:31






  • 1




    For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
    – Julio Daniel Reyes
    Nov 9 at 21:35
















  • InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
    – Deadpool
    Nov 9 at 20:08










  • @Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
    – jlp
    Nov 9 at 20:10











  • what does your POM look like?
    – Darren Forsythe
    Nov 9 at 20:15






  • 1




    Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
    – Julio Daniel Reyes
    Nov 9 at 21:31






  • 1




    For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
    – Julio Daniel Reyes
    Nov 9 at 21:35















InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
– Deadpool
Nov 9 at 20:08




InstantDeserializer.class is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
– Deadpool
Nov 9 at 20:08












@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10





@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10













what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15




what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15




1




1




Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31




Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31




1




1




For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35




For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer. (Take as example the code in InstantDeserializer for the arguments of super())



public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime> 
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);




Then you can use it:



@JsonDeserialize(using = DefaultInstantDeserializer.class)





share|improve this answer




















    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',
    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%2f53232600%2fjava-8-exception-com-fasterxml-jackson-datatype-jsr310-deser-instantdeserialize%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer. (Take as example the code in InstantDeserializer for the arguments of super())



    public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime> 
    public DefaultInstantDeserializer()
    super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
    OffsetDateTime::from,
    a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
    a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
    (d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
    true);




    Then you can use it:



    @JsonDeserialize(using = DefaultInstantDeserializer.class)





    share|improve this answer
























      up vote
      1
      down vote



      accepted










      The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer. (Take as example the code in InstantDeserializer for the arguments of super())



      public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime> 
      public DefaultInstantDeserializer()
      super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
      OffsetDateTime::from,
      a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
      a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
      (d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
      true);




      Then you can use it:



      @JsonDeserialize(using = DefaultInstantDeserializer.class)





      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer. (Take as example the code in InstantDeserializer for the arguments of super())



        public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime> 
        public DefaultInstantDeserializer()
        super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
        OffsetDateTime::from,
        a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
        a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
        (d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
        true);




        Then you can use it:



        @JsonDeserialize(using = DefaultInstantDeserializer.class)





        share|improve this answer












        The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer. (Take as example the code in InstantDeserializer for the arguments of super())



        public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime> 
        public DefaultInstantDeserializer()
        super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
        OffsetDateTime::from,
        a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
        a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
        (d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
        true);




        Then you can use it:



        @JsonDeserialize(using = DefaultInstantDeserializer.class)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 4:30









        Julio Daniel Reyes

        1,977815




        1,977815



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232600%2fjava-8-exception-com-fasterxml-jackson-datatype-jsr310-deser-instantdeserialize%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

            Darth Vader #20

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Ondo