Jackson does not store xml values in object2019 Community Moderator ElectionIs Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?How does the Java 'for each' loop work?Sort a Map<Key, Value> by valuesHow to get an enum value from a string value in Java?Does Java support default parameter values?How do I determine whether an array contains a particular value in Java?Ignoring new fields on JSON objects using JacksonHow to use Jackson to deserialise an array of objectsWhy does this code using random strings print “hello world”?
Recruiter wants very extensive technical details about all of my previous work
World War I as a war of liberals against authoritarians?
Print a physical multiplication table
How are passwords stolen from companies if they only store hashes?
Why Choose Less Effective Armour Types?
Is it insecure to send a password in a `curl` command?
How could an airship be repaired midflight?
When to use a slotted vs. solid turner?
Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?
Why is the President allowed to veto a cancellation of emergency powers?
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
What did “the good wine” (τὸν καλὸν οἶνον) mean in John 2:10?
Python if-else code style for reduced code for rounding floats
How difficult is it to simply disable/disengage the MCAS on Boeing 737 Max 8 & 9 Aircraft?
Why one should not leave fingerprints on bulbs and plugs?
What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
What is the adequate fee for a reveal operation?
Professor being mistaken for a grad student
What is the significance behind "40 days" that often appears in the Bible?
Why does a Star of David appear at a rally with Francisco Franco?
Why did it take so long to abandon sail after steamships were demonstrated?
Did Ender ever learn that he killed Stilson and/or Bonzo?
About the actual radiative impact of greenhouse gas emission over time
Jackson does not store xml values in object
2019 Community Moderator ElectionIs Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?How does the Java 'for each' loop work?Sort a Map<Key, Value> by valuesHow to get an enum value from a string value in Java?Does Java support default parameter values?How do I determine whether an array contains a particular value in Java?Ignoring new fields on JSON objects using JacksonHow to use Jackson to deserialise an array of objectsWhy does this code using random strings print “hello world”?
I have an XML file like this:
"<?xml version ='1.0' encoding='UFT-8'?>"+
"<CLOSE_TRAILER>"+
"<user>" +
"<id>0600580</id>" +
"<trans_id>7</trans_id>" +
"<host_name>Mnull</host_name>"+
"<session_token>79430831Zahyy</session_token>" +
"<time_stamp>1551736026682</time_stamp>" +
"</user>"+
"<trailer_detail>" +
"<org_id>432</org_id>" +
"<trailer_prefix>XTRA</trailer_prefix>" +
"<system_type>SCAN</system_type>" +
"<truck_mail_flag>false</truck_mail_flag>" +
"<trailer_type_code>T</trailer_type_code>" +
"<in_contingency_flag>false</in_contingency_flag>" +
"<detl_code_svc_type>OVN</detl_code_svc_type>" +
"<catg_code_svc_type></catg_code_svc_type>" +
"<seal_number>12345</seal_number>" +
"<user_id>5155035</user_id>" +
"<trailer_number>24813</trailer_number>" +
"</trailer_detail>"+
"<load_handler>" +
"<employee_id>TEST</employee_id>" +
"<trailer_load_seq>71373839</trailer_load_seq>" +
"<action_code></action_code>" +
"</load_handler>"+
"</CLOSE_TRAILER>";
I want to map the trailer_detail and load_handler but not user, it into this object that I created for this xml:
@JsonRootName(value = "CLOSE_TRAILER")
public class CloseTrailerXml
@JsonUnwrapped
Trailer trailer_detail;
@JsonUnwrapped
LoadHandler load_handler;
The Trailer class I have mapped like this:
@JsonRootName("trailer_detail")
public class Trailer {
private Integer equipmentSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
@JsonProperty("trailer_number")
private String trlrNbr;
... more member variables
In a unit test case I have the above xml stored as a string and I use this code below to map it into the object:
String msgNoNewLineChar = originalScannerMsg.replace("\n","");
String msgNoCarReturnChar = msgNoNewLineChar.replace("\r", "");
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setSerializationInclusion(Include.NON_NULL);
CloseTrailerXml closeTrailerXml= xmlMapper.readValue(originalScannerMsg, CloseTrailerXml.class);
The closeTrailerXml is created but all values are null.
If I remove the encoding line and CLOSE_TRAILER tag and the user section, it maps fine.
Why can't the object mapper work with the user section present?
java jackson-dataformat-xml
add a comment |
I have an XML file like this:
"<?xml version ='1.0' encoding='UFT-8'?>"+
"<CLOSE_TRAILER>"+
"<user>" +
"<id>0600580</id>" +
"<trans_id>7</trans_id>" +
"<host_name>Mnull</host_name>"+
"<session_token>79430831Zahyy</session_token>" +
"<time_stamp>1551736026682</time_stamp>" +
"</user>"+
"<trailer_detail>" +
"<org_id>432</org_id>" +
"<trailer_prefix>XTRA</trailer_prefix>" +
"<system_type>SCAN</system_type>" +
"<truck_mail_flag>false</truck_mail_flag>" +
"<trailer_type_code>T</trailer_type_code>" +
"<in_contingency_flag>false</in_contingency_flag>" +
"<detl_code_svc_type>OVN</detl_code_svc_type>" +
"<catg_code_svc_type></catg_code_svc_type>" +
"<seal_number>12345</seal_number>" +
"<user_id>5155035</user_id>" +
"<trailer_number>24813</trailer_number>" +
"</trailer_detail>"+
"<load_handler>" +
"<employee_id>TEST</employee_id>" +
"<trailer_load_seq>71373839</trailer_load_seq>" +
"<action_code></action_code>" +
"</load_handler>"+
"</CLOSE_TRAILER>";
I want to map the trailer_detail and load_handler but not user, it into this object that I created for this xml:
@JsonRootName(value = "CLOSE_TRAILER")
public class CloseTrailerXml
@JsonUnwrapped
Trailer trailer_detail;
@JsonUnwrapped
LoadHandler load_handler;
The Trailer class I have mapped like this:
@JsonRootName("trailer_detail")
public class Trailer {
private Integer equipmentSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
@JsonProperty("trailer_number")
private String trlrNbr;
... more member variables
In a unit test case I have the above xml stored as a string and I use this code below to map it into the object:
String msgNoNewLineChar = originalScannerMsg.replace("\n","");
String msgNoCarReturnChar = msgNoNewLineChar.replace("\r", "");
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setSerializationInclusion(Include.NON_NULL);
CloseTrailerXml closeTrailerXml= xmlMapper.readValue(originalScannerMsg, CloseTrailerXml.class);
The closeTrailerXml is created but all values are null.
If I remove the encoding line and CLOSE_TRAILER tag and the user section, it maps fine.
Why can't the object mapper work with the user section present?
java jackson-dataformat-xml
For starters, your encoding is wrong. It should beUTF-8
. This is likely to cause problems.
– chrylis
Mar 6 at 21:51
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31
add a comment |
I have an XML file like this:
"<?xml version ='1.0' encoding='UFT-8'?>"+
"<CLOSE_TRAILER>"+
"<user>" +
"<id>0600580</id>" +
"<trans_id>7</trans_id>" +
"<host_name>Mnull</host_name>"+
"<session_token>79430831Zahyy</session_token>" +
"<time_stamp>1551736026682</time_stamp>" +
"</user>"+
"<trailer_detail>" +
"<org_id>432</org_id>" +
"<trailer_prefix>XTRA</trailer_prefix>" +
"<system_type>SCAN</system_type>" +
"<truck_mail_flag>false</truck_mail_flag>" +
"<trailer_type_code>T</trailer_type_code>" +
"<in_contingency_flag>false</in_contingency_flag>" +
"<detl_code_svc_type>OVN</detl_code_svc_type>" +
"<catg_code_svc_type></catg_code_svc_type>" +
"<seal_number>12345</seal_number>" +
"<user_id>5155035</user_id>" +
"<trailer_number>24813</trailer_number>" +
"</trailer_detail>"+
"<load_handler>" +
"<employee_id>TEST</employee_id>" +
"<trailer_load_seq>71373839</trailer_load_seq>" +
"<action_code></action_code>" +
"</load_handler>"+
"</CLOSE_TRAILER>";
I want to map the trailer_detail and load_handler but not user, it into this object that I created for this xml:
@JsonRootName(value = "CLOSE_TRAILER")
public class CloseTrailerXml
@JsonUnwrapped
Trailer trailer_detail;
@JsonUnwrapped
LoadHandler load_handler;
The Trailer class I have mapped like this:
@JsonRootName("trailer_detail")
public class Trailer {
private Integer equipmentSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
@JsonProperty("trailer_number")
private String trlrNbr;
... more member variables
In a unit test case I have the above xml stored as a string and I use this code below to map it into the object:
String msgNoNewLineChar = originalScannerMsg.replace("\n","");
String msgNoCarReturnChar = msgNoNewLineChar.replace("\r", "");
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setSerializationInclusion(Include.NON_NULL);
CloseTrailerXml closeTrailerXml= xmlMapper.readValue(originalScannerMsg, CloseTrailerXml.class);
The closeTrailerXml is created but all values are null.
If I remove the encoding line and CLOSE_TRAILER tag and the user section, it maps fine.
Why can't the object mapper work with the user section present?
java jackson-dataformat-xml
I have an XML file like this:
"<?xml version ='1.0' encoding='UFT-8'?>"+
"<CLOSE_TRAILER>"+
"<user>" +
"<id>0600580</id>" +
"<trans_id>7</trans_id>" +
"<host_name>Mnull</host_name>"+
"<session_token>79430831Zahyy</session_token>" +
"<time_stamp>1551736026682</time_stamp>" +
"</user>"+
"<trailer_detail>" +
"<org_id>432</org_id>" +
"<trailer_prefix>XTRA</trailer_prefix>" +
"<system_type>SCAN</system_type>" +
"<truck_mail_flag>false</truck_mail_flag>" +
"<trailer_type_code>T</trailer_type_code>" +
"<in_contingency_flag>false</in_contingency_flag>" +
"<detl_code_svc_type>OVN</detl_code_svc_type>" +
"<catg_code_svc_type></catg_code_svc_type>" +
"<seal_number>12345</seal_number>" +
"<user_id>5155035</user_id>" +
"<trailer_number>24813</trailer_number>" +
"</trailer_detail>"+
"<load_handler>" +
"<employee_id>TEST</employee_id>" +
"<trailer_load_seq>71373839</trailer_load_seq>" +
"<action_code></action_code>" +
"</load_handler>"+
"</CLOSE_TRAILER>";
I want to map the trailer_detail and load_handler but not user, it into this object that I created for this xml:
@JsonRootName(value = "CLOSE_TRAILER")
public class CloseTrailerXml
@JsonUnwrapped
Trailer trailer_detail;
@JsonUnwrapped
LoadHandler load_handler;
The Trailer class I have mapped like this:
@JsonRootName("trailer_detail")
public class Trailer {
private Integer equipmentSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
@JsonProperty("trailer_number")
private String trlrNbr;
... more member variables
In a unit test case I have the above xml stored as a string and I use this code below to map it into the object:
String msgNoNewLineChar = originalScannerMsg.replace("\n","");
String msgNoCarReturnChar = msgNoNewLineChar.replace("\r", "");
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setSerializationInclusion(Include.NON_NULL);
CloseTrailerXml closeTrailerXml= xmlMapper.readValue(originalScannerMsg, CloseTrailerXml.class);
The closeTrailerXml is created but all values are null.
If I remove the encoding line and CLOSE_TRAILER tag and the user section, it maps fine.
Why can't the object mapper work with the user section present?
java jackson-dataformat-xml
java jackson-dataformat-xml
asked Mar 6 at 20:53
Gloria SantinGloria Santin
81611659
81611659
For starters, your encoding is wrong. It should beUTF-8
. This is likely to cause problems.
– chrylis
Mar 6 at 21:51
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31
add a comment |
For starters, your encoding is wrong. It should beUTF-8
. This is likely to cause problems.
– chrylis
Mar 6 at 21:51
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31
For starters, your encoding is wrong. It should be
UTF-8
. This is likely to cause problems.– chrylis
Mar 6 at 21:51
For starters, your encoding is wrong. It should be
UTF-8
. This is likely to cause problems.– chrylis
Mar 6 at 21:51
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031957%2fjackson-does-not-store-xml-values-in-object%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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031957%2fjackson-does-not-store-xml-values-in-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
For starters, your encoding is wrong. It should be
UTF-8
. This is likely to cause problems.– chrylis
Mar 6 at 21:51
This xml file cannot be edited. It is coming from another application.
– Gloria Santin
Mar 7 at 0:31