MismatchInputException when Deserializing String to ZonedDateTime using JacksonHow to generate a random alpha-numeric string?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How to get an enum value from a string value in Java?How to split a string in JavaHow do I convert a String to an int in Java?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?ObjectMapper can't map the variables of inner classJackson json formatting of zoneddatetime

Multiplicative persistence

Can I say "fingers" when referring to toes?

Hero deduces identity of a killer

Can a Canadian Travel to the USA twice, less than 180 days each time?

Strong empirical falsification of quantum mechanics based on vacuum energy density

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

How does a computer interpret real numbers?

Fear of getting stuck on one programming language / technology that is not used in my country

What if a revenant (monster) gains fire resistance?

Yosemite Fire Rings - What to Expect?

The IT department bottlenecks progress. How should I handle this?

How to fade a semiplane defined by line?

Recommended PCB layout understanding - ADM2572 datasheet

Temporarily disable WLAN internet access for children, but allow it for adults

How do you make your own symbol when Detexify fails?

How can I write humor as character trait?

Can a College of Swords bard use a Blade Flourish option on an opportunity attack provoked by their own Dissonant Whispers spell?

Why "had" in "[something] we would have made had we used [something]"?

Does the UK parliament need to pass secondary legislation to accept the Article 50 extension

It grows, but water kills it

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

What are the advantages of simplicial model categories over non-simplicial ones?

How to rewrite equation of hyperbola in standard form

Why should universal income be universal?



MismatchInputException when Deserializing String to ZonedDateTime using Jackson


How to generate a random alpha-numeric string?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How to get an enum value from a string value in Java?How to split a string in JavaHow do I convert a String to an int in Java?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?ObjectMapper can't map the variables of inner classJackson json formatting of zoneddatetime













0















I have a date/time value, openDtGmt, is part of an xml input from a legacy system that cannot be changed.
An example of the date/time: 2019 3 4 14 44 20 -5
I am using Jackson to map the xml into an object.
I created a custom Deserialize class to map this string into a ZonedDateTime object.
When running the unit test I get the error:




com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
construct instance of
com.fedex.ground.tms.javaserver.dock.closetrailer.model.StandardLoadComposite
(although at least one Creator exists): no String-argument
constructor/factory method to deserialize from String value ('2019 3 4
14 44 20 -5')




This date is in a class TrailerLoad which is part of StandardLoadComposite which is part of the parent class CloseTrailerXml
This is the classes:



class CloseTrailerXml 
@JacksonXmlElementWrapper(localName = "trailer_standard_loads", useWrapping = true)
List<StandardLoadComposite> trailer_standard_loads;

...other classes


@JsonIgnoreProperties(ignoreUnknown=true)
public class StandardLoadComposite

public StandardLoadComposite()

@JsonUnwrapped
private TrailerLoad trailerload;

...other classes


@JsonRootName("trailer_standard_loads")
@JsonIgnoreProperties(ignoreUnknown=true)
public class TrailerLoad

private Integer trailerLoadSeq;
@JsonProperty("open_dt_gmt") //this is the datetime deserialized
private ZonedDateTime openDtGmt;
...other member variables



Now the Deserializer:



public class ZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {

protected final Log log = LogFactory.getLog(TMSTransactionBean.class.getName());

@Override
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctx)
throws IOException
String dateTimeString = p.getText();

try
..string manipulation...
dateTimeFromString = ZonedDateTime.parse(formattedDateTimeString);
return dateTimeFromString;
catch (DateTimeParseException e)
log.error("Error deserializing the date from scanner xml message: " + e.getMessage());
return null;




This is the call to map the xml to the object:



 //creating a module
SimpleModule module = new SimpleModule();
module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());

XmlMapper xmlMapper = new XmlMapper();
xmlMapper.registerModule(new JavaTimeModule());
xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
xmlMapper.registerModule(module);

xmlMapper.setSerializationInclusion(Include.NON_NULL);

CloseTrailerXml closeTrailerXml = xmlMapper.readValue(message, CloseTrailerXml.class);


I just want to deserialize one field in the TrailerLoad class. The error is that the StandardLoadComposite class does not have a constructor for the date string. The date is actually in the TrailerLoad class that is in the StandardLoadComposite.
I don't understand how to create the constructor for date field that is a string in the xml to the ZonedDateTime in the TrailerLoad class.










share|improve this question




























    0















    I have a date/time value, openDtGmt, is part of an xml input from a legacy system that cannot be changed.
    An example of the date/time: 2019 3 4 14 44 20 -5
    I am using Jackson to map the xml into an object.
    I created a custom Deserialize class to map this string into a ZonedDateTime object.
    When running the unit test I get the error:




    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
    construct instance of
    com.fedex.ground.tms.javaserver.dock.closetrailer.model.StandardLoadComposite
    (although at least one Creator exists): no String-argument
    constructor/factory method to deserialize from String value ('2019 3 4
    14 44 20 -5')




    This date is in a class TrailerLoad which is part of StandardLoadComposite which is part of the parent class CloseTrailerXml
    This is the classes:



    class CloseTrailerXml 
    @JacksonXmlElementWrapper(localName = "trailer_standard_loads", useWrapping = true)
    List<StandardLoadComposite> trailer_standard_loads;

    ...other classes


    @JsonIgnoreProperties(ignoreUnknown=true)
    public class StandardLoadComposite

    public StandardLoadComposite()

    @JsonUnwrapped
    private TrailerLoad trailerload;

    ...other classes


    @JsonRootName("trailer_standard_loads")
    @JsonIgnoreProperties(ignoreUnknown=true)
    public class TrailerLoad

    private Integer trailerLoadSeq;
    @JsonProperty("open_dt_gmt") //this is the datetime deserialized
    private ZonedDateTime openDtGmt;
    ...other member variables



    Now the Deserializer:



    public class ZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {

    protected final Log log = LogFactory.getLog(TMSTransactionBean.class.getName());

    @Override
    public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctx)
    throws IOException
    String dateTimeString = p.getText();

    try
    ..string manipulation...
    dateTimeFromString = ZonedDateTime.parse(formattedDateTimeString);
    return dateTimeFromString;
    catch (DateTimeParseException e)
    log.error("Error deserializing the date from scanner xml message: " + e.getMessage());
    return null;




    This is the call to map the xml to the object:



     //creating a module
    SimpleModule module = new SimpleModule();
    module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());

    XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.registerModule(new JavaTimeModule());
    xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    xmlMapper.registerModule(module);

    xmlMapper.setSerializationInclusion(Include.NON_NULL);

    CloseTrailerXml closeTrailerXml = xmlMapper.readValue(message, CloseTrailerXml.class);


    I just want to deserialize one field in the TrailerLoad class. The error is that the StandardLoadComposite class does not have a constructor for the date string. The date is actually in the TrailerLoad class that is in the StandardLoadComposite.
    I don't understand how to create the constructor for date field that is a string in the xml to the ZonedDateTime in the TrailerLoad class.










    share|improve this question


























      0












      0








      0








      I have a date/time value, openDtGmt, is part of an xml input from a legacy system that cannot be changed.
      An example of the date/time: 2019 3 4 14 44 20 -5
      I am using Jackson to map the xml into an object.
      I created a custom Deserialize class to map this string into a ZonedDateTime object.
      When running the unit test I get the error:




      com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
      construct instance of
      com.fedex.ground.tms.javaserver.dock.closetrailer.model.StandardLoadComposite
      (although at least one Creator exists): no String-argument
      constructor/factory method to deserialize from String value ('2019 3 4
      14 44 20 -5')




      This date is in a class TrailerLoad which is part of StandardLoadComposite which is part of the parent class CloseTrailerXml
      This is the classes:



      class CloseTrailerXml 
      @JacksonXmlElementWrapper(localName = "trailer_standard_loads", useWrapping = true)
      List<StandardLoadComposite> trailer_standard_loads;

      ...other classes


      @JsonIgnoreProperties(ignoreUnknown=true)
      public class StandardLoadComposite

      public StandardLoadComposite()

      @JsonUnwrapped
      private TrailerLoad trailerload;

      ...other classes


      @JsonRootName("trailer_standard_loads")
      @JsonIgnoreProperties(ignoreUnknown=true)
      public class TrailerLoad

      private Integer trailerLoadSeq;
      @JsonProperty("open_dt_gmt") //this is the datetime deserialized
      private ZonedDateTime openDtGmt;
      ...other member variables



      Now the Deserializer:



      public class ZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {

      protected final Log log = LogFactory.getLog(TMSTransactionBean.class.getName());

      @Override
      public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctx)
      throws IOException
      String dateTimeString = p.getText();

      try
      ..string manipulation...
      dateTimeFromString = ZonedDateTime.parse(formattedDateTimeString);
      return dateTimeFromString;
      catch (DateTimeParseException e)
      log.error("Error deserializing the date from scanner xml message: " + e.getMessage());
      return null;




      This is the call to map the xml to the object:



       //creating a module
      SimpleModule module = new SimpleModule();
      module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());

      XmlMapper xmlMapper = new XmlMapper();
      xmlMapper.registerModule(new JavaTimeModule());
      xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
      xmlMapper.registerModule(module);

      xmlMapper.setSerializationInclusion(Include.NON_NULL);

      CloseTrailerXml closeTrailerXml = xmlMapper.readValue(message, CloseTrailerXml.class);


      I just want to deserialize one field in the TrailerLoad class. The error is that the StandardLoadComposite class does not have a constructor for the date string. The date is actually in the TrailerLoad class that is in the StandardLoadComposite.
      I don't understand how to create the constructor for date field that is a string in the xml to the ZonedDateTime in the TrailerLoad class.










      share|improve this question
















      I have a date/time value, openDtGmt, is part of an xml input from a legacy system that cannot be changed.
      An example of the date/time: 2019 3 4 14 44 20 -5
      I am using Jackson to map the xml into an object.
      I created a custom Deserialize class to map this string into a ZonedDateTime object.
      When running the unit test I get the error:




      com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
      construct instance of
      com.fedex.ground.tms.javaserver.dock.closetrailer.model.StandardLoadComposite
      (although at least one Creator exists): no String-argument
      constructor/factory method to deserialize from String value ('2019 3 4
      14 44 20 -5')




      This date is in a class TrailerLoad which is part of StandardLoadComposite which is part of the parent class CloseTrailerXml
      This is the classes:



      class CloseTrailerXml 
      @JacksonXmlElementWrapper(localName = "trailer_standard_loads", useWrapping = true)
      List<StandardLoadComposite> trailer_standard_loads;

      ...other classes


      @JsonIgnoreProperties(ignoreUnknown=true)
      public class StandardLoadComposite

      public StandardLoadComposite()

      @JsonUnwrapped
      private TrailerLoad trailerload;

      ...other classes


      @JsonRootName("trailer_standard_loads")
      @JsonIgnoreProperties(ignoreUnknown=true)
      public class TrailerLoad

      private Integer trailerLoadSeq;
      @JsonProperty("open_dt_gmt") //this is the datetime deserialized
      private ZonedDateTime openDtGmt;
      ...other member variables



      Now the Deserializer:



      public class ZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {

      protected final Log log = LogFactory.getLog(TMSTransactionBean.class.getName());

      @Override
      public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctx)
      throws IOException
      String dateTimeString = p.getText();

      try
      ..string manipulation...
      dateTimeFromString = ZonedDateTime.parse(formattedDateTimeString);
      return dateTimeFromString;
      catch (DateTimeParseException e)
      log.error("Error deserializing the date from scanner xml message: " + e.getMessage());
      return null;




      This is the call to map the xml to the object:



       //creating a module
      SimpleModule module = new SimpleModule();
      module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());

      XmlMapper xmlMapper = new XmlMapper();
      xmlMapper.registerModule(new JavaTimeModule());
      xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
      xmlMapper.registerModule(module);

      xmlMapper.setSerializationInclusion(Include.NON_NULL);

      CloseTrailerXml closeTrailerXml = xmlMapper.readValue(message, CloseTrailerXml.class);


      I just want to deserialize one field in the TrailerLoad class. The error is that the StandardLoadComposite class does not have a constructor for the date string. The date is actually in the TrailerLoad class that is in the StandardLoadComposite.
      I don't understand how to create the constructor for date field that is a string in the xml to the ZonedDateTime in the TrailerLoad class.







      java jackson-dataformat-xml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 2:05







      Gloria Santin

















      asked Mar 8 at 1:20









      Gloria SantinGloria Santin

      81811659




      81811659






















          0






          active

          oldest

          votes











          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%2f55055395%2fmismatchinputexception-when-deserializing-string-to-zoneddatetime-using-jackson%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55055395%2fmismatchinputexception-when-deserializing-string-to-zoneddatetime-using-jackson%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

          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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived