java - Jackson XML module: Multiple fields representing property error when two collection fields' items have the same name -


required xml:

<bean>     <paths>         <path>foo/bar/</path>         <path>x/y</path>     <paths>     <morepaths>          <path>a/b/c</path>          <path>j/k/l</path>     <morepaths>  <bean> 

beware item tags in both collections the same: "path" whether they're wrapped different tags: "paths" , "morepaths"

the annotated bean (using lombok):

@jacksonxmlrootelement(localname="bean")  @accessors(prefix="_") @noargsconstructor @allargsconstructor public static class testbean {     @jacksonxmlelementwrapper(localname="paths") @jacksonxmlproperty(localname="path")     @getter @setter private collection<path> _pathcol;      @jacksonxmlelementwrapper(localname="otherpaths") @jacksonxmlproperty(localname="path")     @getter @setter private collection<path> _otherpathcol; } 

problem: when mapping exception thrown saying there're 2 properties mapped same tag (path)

@test public void test() throws ioexception  {     xmlmapper xmlmapper = new xmlmapper();     testbean mybean = new testbean(lists.<path>newarraylist(path.from("/a/b/c"),                                                             path.from("d/e/f")),                                    lists.<path>newarraylist(path.from("/foo/bar/baz"),                                                             path.from("x/y/z")));     system.out.println("xml: " + xmlmapper.writevalueasstring(mybean));         } 

exception:

com.fasterxml.jackson.databind.jsonmappingexception: multiple fields representing property "path" 

if diferent property names used, works:

@jacksonxmlrootelement(localname="bean")  @accessors(prefix="_") @noargsconstructor @allargsconstructor public static class testbean {     @jacksonxmlelementwrapper(localname="paths") @jacksonxmlproperty(localname="paths_path")     @getter @setter private collection<path> _pathcol;      @jacksonxmlelementwrapper(localname="otherpaths") @jacksonxmlproperty(localname="otherpaths_path")     @getter @setter private collection<path> _otherpathcol; } 

but, xml output not required one:

<bean>     <paths>         <paths_path>foo/bar/</paths_path>         <paths_path>x/y</paths_path>     <paths>     <morepaths>          <morepaths_path>a/b/c</morepaths_path>          <morepaths_path>j/k/l</morepaths_path>     <morepaths>  <bean> 

how can manage items same tag in both collections?

note: it's known issue (see: https://github.com/fasterxml/jackson-dataformat-xml/issues/192) ... don't know if there's workarround


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -