changing mapping field for @XmlValue in @JsonPropertyHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesWhy does Java have transient fields?Jackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonJackson json deserialization, ignore root element from jsonHow to tell Jackson to ignore a field during serialization if its value is null?Jerkson JsonProperty not workingJackson Mixin not working for deserializing non-default constructor object@JsonProperty not mapping the value to POJO
Can I activate an iPhone without an Apple ID?
Filtering fine silt/mud from water (not necessarily bacteria etc.)
Is it rude to tell recruiters I would only change jobs for a better salary?
How do I define this subset using mathematical notation?
Why hasn't the U.S. government paid war reparations to any country it attacked?
Ezek. 24:1-2, "Again in the ninth year, in the tenth month, in the tenth day of the month, ...." Which month was the tenth month?
What is this old "lemon-squeezer" shaped pan
Why is "dark" an adverb in this sentence?
Published paper containing well-known results
Old short story where the future emperor of the galaxy is taken for a tour around Earth
What is the closed form of the following recursive function?
Can I capture stereo IQ signals from WebSDR?
Do native speakers use ZVE or CPU?
3D-Plot with an inequality condition for parameter values
Are there any double stars that I can actually see orbit each other?
HackerRank: Electronics Shop
Can a continent naturally split into two distant parts within a week?
Is it okay to retroactively change things when running a published adventure?
How would someone destroy a black hole that’s at the centre of a planet?
Add region constraint to Graphics
Why is the collector feedback bias popular in electret-mic preamp circuits?
Concatenation using + and += operator in Python
Why does Hellboy file down his horns?
Variation in the spelling of word-final M
changing mapping field for @XmlValue in @JsonProperty
How do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesWhy does Java have transient fields?Jackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonJackson json deserialization, ignore root element from jsonHow to tell Jackson to ignore a field during serialization if its value is null?Jerkson JsonProperty not workingJackson Mixin not working for deserializing non-default constructor object@JsonProperty not mapping the value to POJO
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an element "SubElement2" that has value and attribute.
Working :
My Annotation are
@XmlValue
@JsonProperty(value="content")
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
TO JSON :
"SubElement2" :
"content" : "ELEMENT_2_TAG_VAL",
"parameterName" : "tested"
Here I want to change the property name content to myOwnContent
Not Working:
Modified annotations :
@XmlValue
@JsonProperty(value="myOwnContent") // Modified
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
For the above annotation change, I'm facing below exception:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "content" (class SubElement2), not marked as ignorable (2 known properties: "parameterName", "myOwnContent"])
at [Source: (String)""SubElement2":"parameterName":"tested","content":"ELEMENT_2_TAG_VAL""; line: 1, column: 53] (through reference chain: Element1["SubElement2"]->SubElement2["content"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
Below is my code :
ObjectFactory.java
@XmlRegistry
public class ObjectFactory
public SubElement2 createSubElement2()
return new SubElement2();
MainProgram.java
public class MainProgram
public static void main(String[] args) throws ClassNotFoundException, IOException
String request = "<SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>";
System.out.println("Request in XML : "+request);
JSONObject jObject = XML.toJSONObject(request);
ObjectMapper mapper = createCombinedObjectMapper();
Object json = mapper.readValue(jObject.toString(), Class.forName("Element1"));
String output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
System.out.println(output);
private static ObjectMapper createCombinedObjectMapper()
return new ObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector()
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
SubElement2.java
@XmlRootElement(name = "SubElement2")
public class SubElement2
@XmlValue
@JsonProperty(value="myOwnContent")
private String value;
@JsonProperty(value="parameterName",required=true)
@XmlAttribute(required = true)
protected String parameterName;
public String getValue()
return value;
public void setValue(String value)
this.value = value;
public String getParameterName()
return parameterName;
public void setParameterName(String parameterName)
this.parameterName = parameterName;
Element1.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "element1", propOrder =
"element1"
)
@XmlRootElement(name = "Element1")
public class Element1
@XmlElement(name="SubElement2")
protected SubElement2 subElement2;
public SubElement2 getSubElement2()
return subElement2;
public void setSubElement2(SubElement2 subElement2)
this.subElement2 = subElement2;
I'm using Jackson version : 2.9.7
Help me to solve this exception ,thanks in advance
What I want to do :
I want to have jsonproperty as myOwnContent
because content
is already used by another attribute in XML
in my existing implementation. (Existing implementation doesn't have JSON suuport , we are adding JSON support)
java json xml jackson swagger
add a comment |
I have an element "SubElement2" that has value and attribute.
Working :
My Annotation are
@XmlValue
@JsonProperty(value="content")
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
TO JSON :
"SubElement2" :
"content" : "ELEMENT_2_TAG_VAL",
"parameterName" : "tested"
Here I want to change the property name content to myOwnContent
Not Working:
Modified annotations :
@XmlValue
@JsonProperty(value="myOwnContent") // Modified
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
For the above annotation change, I'm facing below exception:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "content" (class SubElement2), not marked as ignorable (2 known properties: "parameterName", "myOwnContent"])
at [Source: (String)""SubElement2":"parameterName":"tested","content":"ELEMENT_2_TAG_VAL""; line: 1, column: 53] (through reference chain: Element1["SubElement2"]->SubElement2["content"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
Below is my code :
ObjectFactory.java
@XmlRegistry
public class ObjectFactory
public SubElement2 createSubElement2()
return new SubElement2();
MainProgram.java
public class MainProgram
public static void main(String[] args) throws ClassNotFoundException, IOException
String request = "<SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>";
System.out.println("Request in XML : "+request);
JSONObject jObject = XML.toJSONObject(request);
ObjectMapper mapper = createCombinedObjectMapper();
Object json = mapper.readValue(jObject.toString(), Class.forName("Element1"));
String output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
System.out.println(output);
private static ObjectMapper createCombinedObjectMapper()
return new ObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector()
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
SubElement2.java
@XmlRootElement(name = "SubElement2")
public class SubElement2
@XmlValue
@JsonProperty(value="myOwnContent")
private String value;
@JsonProperty(value="parameterName",required=true)
@XmlAttribute(required = true)
protected String parameterName;
public String getValue()
return value;
public void setValue(String value)
this.value = value;
public String getParameterName()
return parameterName;
public void setParameterName(String parameterName)
this.parameterName = parameterName;
Element1.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "element1", propOrder =
"element1"
)
@XmlRootElement(name = "Element1")
public class Element1
@XmlElement(name="SubElement2")
protected SubElement2 subElement2;
public SubElement2 getSubElement2()
return subElement2;
public void setSubElement2(SubElement2 subElement2)
this.subElement2 = subElement2;
I'm using Jackson version : 2.9.7
Help me to solve this exception ,thanks in advance
What I want to do :
I want to have jsonproperty as myOwnContent
because content
is already used by another attribute in XML
in my existing implementation. (Existing implementation doesn't have JSON suuport , we are adding JSON support)
java json xml jackson swagger
Why do you want to deserialise resultJSON
toElement1
? You deserialiseXML
payload toSubElement2
class and after that probably serialiseSubElement2
instance toJSON
(JSONObject
?!?). Later you want to deserialise it toElement1
butElement1
does not match toSubElement2
. Why you do not deserialise it toSubElement2
?
– Michał Ziober
Mar 26 at 21:41
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty asmyOwnContent
becausecontent
is already used by another attribute inXML
– theRoot
Mar 27 at 7:13
I checked flow inmain
method and it looks like you convertXML
toJSON
and after that try to deserialiseJSON
toElement1
but givenXML
fits toSubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behindXML.toJSONObject(request)
. Also, why do you load class byClass.forName("Element1")
?
– Michał Ziober
Mar 27 at 8:43
add a comment |
I have an element "SubElement2" that has value and attribute.
Working :
My Annotation are
@XmlValue
@JsonProperty(value="content")
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
TO JSON :
"SubElement2" :
"content" : "ELEMENT_2_TAG_VAL",
"parameterName" : "tested"
Here I want to change the property name content to myOwnContent
Not Working:
Modified annotations :
@XmlValue
@JsonProperty(value="myOwnContent") // Modified
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
For the above annotation change, I'm facing below exception:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "content" (class SubElement2), not marked as ignorable (2 known properties: "parameterName", "myOwnContent"])
at [Source: (String)""SubElement2":"parameterName":"tested","content":"ELEMENT_2_TAG_VAL""; line: 1, column: 53] (through reference chain: Element1["SubElement2"]->SubElement2["content"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
Below is my code :
ObjectFactory.java
@XmlRegistry
public class ObjectFactory
public SubElement2 createSubElement2()
return new SubElement2();
MainProgram.java
public class MainProgram
public static void main(String[] args) throws ClassNotFoundException, IOException
String request = "<SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>";
System.out.println("Request in XML : "+request);
JSONObject jObject = XML.toJSONObject(request);
ObjectMapper mapper = createCombinedObjectMapper();
Object json = mapper.readValue(jObject.toString(), Class.forName("Element1"));
String output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
System.out.println(output);
private static ObjectMapper createCombinedObjectMapper()
return new ObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector()
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
SubElement2.java
@XmlRootElement(name = "SubElement2")
public class SubElement2
@XmlValue
@JsonProperty(value="myOwnContent")
private String value;
@JsonProperty(value="parameterName",required=true)
@XmlAttribute(required = true)
protected String parameterName;
public String getValue()
return value;
public void setValue(String value)
this.value = value;
public String getParameterName()
return parameterName;
public void setParameterName(String parameterName)
this.parameterName = parameterName;
Element1.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "element1", propOrder =
"element1"
)
@XmlRootElement(name = "Element1")
public class Element1
@XmlElement(name="SubElement2")
protected SubElement2 subElement2;
public SubElement2 getSubElement2()
return subElement2;
public void setSubElement2(SubElement2 subElement2)
this.subElement2 = subElement2;
I'm using Jackson version : 2.9.7
Help me to solve this exception ,thanks in advance
What I want to do :
I want to have jsonproperty as myOwnContent
because content
is already used by another attribute in XML
in my existing implementation. (Existing implementation doesn't have JSON suuport , we are adding JSON support)
java json xml jackson swagger
I have an element "SubElement2" that has value and attribute.
Working :
My Annotation are
@XmlValue
@JsonProperty(value="content")
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
TO JSON :
"SubElement2" :
"content" : "ELEMENT_2_TAG_VAL",
"parameterName" : "tested"
Here I want to change the property name content to myOwnContent
Not Working:
Modified annotations :
@XmlValue
@JsonProperty(value="myOwnContent") // Modified
private String value;
Request in XML : <SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>
For the above annotation change, I'm facing below exception:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "content" (class SubElement2), not marked as ignorable (2 known properties: "parameterName", "myOwnContent"])
at [Source: (String)""SubElement2":"parameterName":"tested","content":"ELEMENT_2_TAG_VAL""; line: 1, column: 53] (through reference chain: Element1["SubElement2"]->SubElement2["content"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
Below is my code :
ObjectFactory.java
@XmlRegistry
public class ObjectFactory
public SubElement2 createSubElement2()
return new SubElement2();
MainProgram.java
public class MainProgram
public static void main(String[] args) throws ClassNotFoundException, IOException
String request = "<SubElement2 parameterName = "tested">ELEMENT_2_TAG_VAL</SubElement2>";
System.out.println("Request in XML : "+request);
JSONObject jObject = XML.toJSONObject(request);
ObjectMapper mapper = createCombinedObjectMapper();
Object json = mapper.readValue(jObject.toString(), Class.forName("Element1"));
String output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
System.out.println(output);
private static ObjectMapper createCombinedObjectMapper()
return new ObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector()
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
SubElement2.java
@XmlRootElement(name = "SubElement2")
public class SubElement2
@XmlValue
@JsonProperty(value="myOwnContent")
private String value;
@JsonProperty(value="parameterName",required=true)
@XmlAttribute(required = true)
protected String parameterName;
public String getValue()
return value;
public void setValue(String value)
this.value = value;
public String getParameterName()
return parameterName;
public void setParameterName(String parameterName)
this.parameterName = parameterName;
Element1.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "element1", propOrder =
"element1"
)
@XmlRootElement(name = "Element1")
public class Element1
@XmlElement(name="SubElement2")
protected SubElement2 subElement2;
public SubElement2 getSubElement2()
return subElement2;
public void setSubElement2(SubElement2 subElement2)
this.subElement2 = subElement2;
I'm using Jackson version : 2.9.7
Help me to solve this exception ,thanks in advance
What I want to do :
I want to have jsonproperty as myOwnContent
because content
is already used by another attribute in XML
in my existing implementation. (Existing implementation doesn't have JSON suuport , we are adding JSON support)
java json xml jackson swagger
java json xml jackson swagger
edited Mar 27 at 7:15
theRoot
asked Mar 26 at 6:37
theRoottheRoot
4345 silver badges26 bronze badges
4345 silver badges26 bronze badges
Why do you want to deserialise resultJSON
toElement1
? You deserialiseXML
payload toSubElement2
class and after that probably serialiseSubElement2
instance toJSON
(JSONObject
?!?). Later you want to deserialise it toElement1
butElement1
does not match toSubElement2
. Why you do not deserialise it toSubElement2
?
– Michał Ziober
Mar 26 at 21:41
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty asmyOwnContent
becausecontent
is already used by another attribute inXML
– theRoot
Mar 27 at 7:13
I checked flow inmain
method and it looks like you convertXML
toJSON
and after that try to deserialiseJSON
toElement1
but givenXML
fits toSubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behindXML.toJSONObject(request)
. Also, why do you load class byClass.forName("Element1")
?
– Michał Ziober
Mar 27 at 8:43
add a comment |
Why do you want to deserialise resultJSON
toElement1
? You deserialiseXML
payload toSubElement2
class and after that probably serialiseSubElement2
instance toJSON
(JSONObject
?!?). Later you want to deserialise it toElement1
butElement1
does not match toSubElement2
. Why you do not deserialise it toSubElement2
?
– Michał Ziober
Mar 26 at 21:41
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty asmyOwnContent
becausecontent
is already used by another attribute inXML
– theRoot
Mar 27 at 7:13
I checked flow inmain
method and it looks like you convertXML
toJSON
and after that try to deserialiseJSON
toElement1
but givenXML
fits toSubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behindXML.toJSONObject(request)
. Also, why do you load class byClass.forName("Element1")
?
– Michał Ziober
Mar 27 at 8:43
Why do you want to deserialise result
JSON
to Element1
? You deserialise XML
payload to SubElement2
class and after that probably serialise SubElement2
instance to JSON
(JSONObject
?!?). Later you want to deserialise it to Element1
but Element1
does not match to SubElement2
. Why you do not deserialise it to SubElement2
?– Michał Ziober
Mar 26 at 21:41
Why do you want to deserialise result
JSON
to Element1
? You deserialise XML
payload to SubElement2
class and after that probably serialise SubElement2
instance to JSON
(JSONObject
?!?). Later you want to deserialise it to Element1
but Element1
does not match to SubElement2
. Why you do not deserialise it to SubElement2
?– Michał Ziober
Mar 26 at 21:41
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty as
myOwnContent
because content
is already used by another attribute in XML
– theRoot
Mar 27 at 7:13
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty as
myOwnContent
because content
is already used by another attribute in XML
– theRoot
Mar 27 at 7:13
I checked flow in
main
method and it looks like you convert XML
to JSON
and after that try to deserialise JSON
to Element1
but given XML
fits to SubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behind XML.toJSONObject(request)
. Also, why do you load class by Class.forName("Element1")
?– Michał Ziober
Mar 27 at 8:43
I checked flow in
main
method and it looks like you convert XML
to JSON
and after that try to deserialise JSON
to Element1
but given XML
fits to SubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behind XML.toJSONObject(request)
. Also, why do you load class by Class.forName("Element1")
?– Michał Ziober
Mar 27 at 8:43
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%2f55351127%2fchanging-mapping-field-for-xmlvalue-in-jsonproperty%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
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
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%2f55351127%2fchanging-mapping-field-for-xmlvalue-in-jsonproperty%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
Why do you want to deserialise result
JSON
toElement1
? You deserialiseXML
payload toSubElement2
class and after that probably serialiseSubElement2
instance toJSON
(JSONObject
?!?). Later you want to deserialise it toElement1
butElement1
does not match toSubElement2
. Why you do not deserialise it toSubElement2
?– Michał Ziober
Mar 26 at 21:41
Sorry,I don't understand what you are asking , but one thing I want to have jsonproperty as
myOwnContent
becausecontent
is already used by another attribute inXML
– theRoot
Mar 27 at 7:13
I checked flow in
main
method and it looks like you convertXML
toJSON
and after that try to deserialiseJSON
toElement1
but givenXML
fits toSubElement2
. Could you please create runnable example which shows the error? Right now I do not know what is going on behindXML.toJSONObject(request)
. Also, why do you load class byClass.forName("Element1")
?– Michał Ziober
Mar 27 at 8:43