simplexml convertor always write java class name as xml root tag











up vote
1
down vote

favorite












I'm using Retrofit2 as REST client and SimpleXmlConverterFactory for converting from Java to xml, and from xml to Java object.



When I send response with NotificationResponse through REST, no one of the anotations seem to be applied.



@Root(name = "response")
public class NotificationResponse {
@Element(name="message")
private String msg;
@Element(name="version")
private String ver;
}


Instead of :



<response>
<message>Hello</message>
<version>1</version>
</response>


I'm sending:



<NotificationResponse>
<msg>Hello</msg>
<ver>1</ver>
</NotificationResponse>


Any idea, why @Root and @Element are ignored?










share|improve this question






















  • Are you sure that you've use right converter to serialize object?
    – Ivan Zelenskyy
    Nov 19 at 15:05










  • I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
    – Marijana Teofilovic
    Nov 19 at 15:10










  • I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
    – Ivan Zelenskyy
    Nov 19 at 15:28












  • return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
    – Marijana Teofilovic
    Nov 19 at 15:36












  • Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
    – Ivan Zelenskyy
    Nov 19 at 15:56















up vote
1
down vote

favorite












I'm using Retrofit2 as REST client and SimpleXmlConverterFactory for converting from Java to xml, and from xml to Java object.



When I send response with NotificationResponse through REST, no one of the anotations seem to be applied.



@Root(name = "response")
public class NotificationResponse {
@Element(name="message")
private String msg;
@Element(name="version")
private String ver;
}


Instead of :



<response>
<message>Hello</message>
<version>1</version>
</response>


I'm sending:



<NotificationResponse>
<msg>Hello</msg>
<ver>1</ver>
</NotificationResponse>


Any idea, why @Root and @Element are ignored?










share|improve this question






















  • Are you sure that you've use right converter to serialize object?
    – Ivan Zelenskyy
    Nov 19 at 15:05










  • I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
    – Marijana Teofilovic
    Nov 19 at 15:10










  • I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
    – Ivan Zelenskyy
    Nov 19 at 15:28












  • return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
    – Marijana Teofilovic
    Nov 19 at 15:36












  • Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
    – Ivan Zelenskyy
    Nov 19 at 15:56













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm using Retrofit2 as REST client and SimpleXmlConverterFactory for converting from Java to xml, and from xml to Java object.



When I send response with NotificationResponse through REST, no one of the anotations seem to be applied.



@Root(name = "response")
public class NotificationResponse {
@Element(name="message")
private String msg;
@Element(name="version")
private String ver;
}


Instead of :



<response>
<message>Hello</message>
<version>1</version>
</response>


I'm sending:



<NotificationResponse>
<msg>Hello</msg>
<ver>1</ver>
</NotificationResponse>


Any idea, why @Root and @Element are ignored?










share|improve this question













I'm using Retrofit2 as REST client and SimpleXmlConverterFactory for converting from Java to xml, and from xml to Java object.



When I send response with NotificationResponse through REST, no one of the anotations seem to be applied.



@Root(name = "response")
public class NotificationResponse {
@Element(name="message")
private String msg;
@Element(name="version")
private String ver;
}


Instead of :



<response>
<message>Hello</message>
<version>1</version>
</response>


I'm sending:



<NotificationResponse>
<msg>Hello</msg>
<ver>1</ver>
</NotificationResponse>


Any idea, why @Root and @Element are ignored?







java retrofit2 simple-xml-converter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 14:56









Marijana Teofilovic

61




61












  • Are you sure that you've use right converter to serialize object?
    – Ivan Zelenskyy
    Nov 19 at 15:05










  • I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
    – Marijana Teofilovic
    Nov 19 at 15:10










  • I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
    – Ivan Zelenskyy
    Nov 19 at 15:28












  • return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
    – Marijana Teofilovic
    Nov 19 at 15:36












  • Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
    – Ivan Zelenskyy
    Nov 19 at 15:56


















  • Are you sure that you've use right converter to serialize object?
    – Ivan Zelenskyy
    Nov 19 at 15:05










  • I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
    – Marijana Teofilovic
    Nov 19 at 15:10










  • I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
    – Ivan Zelenskyy
    Nov 19 at 15:28












  • return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
    – Marijana Teofilovic
    Nov 19 at 15:36












  • Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
    – Ivan Zelenskyy
    Nov 19 at 15:56
















Are you sure that you've use right converter to serialize object?
– Ivan Zelenskyy
Nov 19 at 15:05




Are you sure that you've use right converter to serialize object?
– Ivan Zelenskyy
Nov 19 at 15:05












I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
– Marijana Teofilovic
Nov 19 at 15:10




I'm using: <dependency> <groupId>com.squareup.retrofit2</groupId> <artifactId>converter-simplexml</artifactId> <version>2.3.0</version> </dependency>
– Marijana Teofilovic
Nov 19 at 15:10












I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
– Ivan Zelenskyy
Nov 19 at 15:28






I mean, how you initialize you converter? I suppose, you have somewhere a code line with "Retrofit.Builder()..."
– Ivan Zelenskyy
Nov 19 at 15:28














return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
– Marijana Teofilovic
Nov 19 at 15:36






return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient()) .addConverterFactory(SimpleXmlConverterFactory.create()) .build();
– Marijana Teofilovic
Nov 19 at 15:36














Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
– Ivan Zelenskyy
Nov 19 at 15:56




Strange. Then, I have no answers, but if SimpleXML is not strict dependency for your project, you can use Gson or JAXB, because SimpleXmlConverterFactory is deprecated in retrofit2 starting from version 2.4.0
– Ivan Zelenskyy
Nov 19 at 15:56

















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',
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%2f53377262%2fsimplexml-convertor-always-write-java-class-name-as-xml-root-tag%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53377262%2fsimplexml-convertor-always-write-java-class-name-as-xml-root-tag%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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?