Hi Tatu,
thanks a lot for the reply. I found an article [1] about the jackson
annotations, which says that it is possible to configure jackson to use
name property of @XmlRootElement.
"@link javax.xml.bind.annotation.XmlRootElement Jackson 1.7
<
http://wiki.fasterxml.com/JacksonRelease17> allows this to be
recognized when root-value wrapping is enabled, and JAXB annotation
introspector is used."
Now I do have the class name included in the json representation,
however, it seems the name specified after @xmlRootElement is not
recognized by jackson.
What I have done now is using 2 annotations, which of course is not a
good solution.
@@JsonTypeName( value = "account" )
@XmlRootElement( name = "account" )
public class MyAccount
{
int x;
}
Best Regards
Pengfei
[1]
http://wiki.fasterxml.com/JacksonJAXBAnnotations
On 03/15/2011 06:25 PM, Tatu Saloranta wrote:
> On Tue, Mar 15, 2011 at 8:54 AM, Pengfei Di<pengfei.di_at_match2blue.com> wrote:
>> Hello,
>>
>> I tried to rename the root element of a jaxb class, that is easy for XML
>> representation. However, it seems impossible for JSON representation.
>> 1. put a JAXBContextResolver, as written in the Example5.5 of jersey guide.
>> 2. add jackson 1.7.0 into the pom.xml. (jackson-core-lgpl 1.7.0 and
>> jackson-mapper-lgpl 1.7.0)
>> Did I miss something?
>>
>> The JAXB class looks like:
>> @XmlRootElement( name = "account" )
>> public class MyAccount
>> {
>> int x;
>> }
> When using Jackson, there will not be a root element (JSON structure
> differs from XML), so you might not be using POJO mapping with Jersey?
> Other json producing methods do add wrapper property.
>
> -+ Tatu +-
--
Pengfei Di
Software Developer Backend
match2blue software development GmbH
Leutragraben 1
07743 Jena
Tel.: +49 3641 573 3474
Fax: +49 3641 573 3479
Email: pengfei.di_at_match2blue.com
Web: http://www.match2blue.com
Blog: http://blog.match2blue.com
Registergericht: Amtsgericht Jena
Registernummer: HRB 503726
Geschäftsführer: Stephanie Renda