You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Craig Tataryn <cr...@tataryn.net> on 2013/07/17 23:57:29 UTC

@XmlElement overriding @JsonProperty

I'm working on a little route for my blog feed, essentially I have a route
that looks like this:

from("rss:...")
.marshal().rss()
.split(xpath("//item"))
.unmarshal(jaxb)
//do stuff to my Article object
.marshal().json(JsonLibrary.Jackson)

My problem is, when I marshal my model object to json I don't want it to
have the same names as the element names from the XML the object was
created from.

So for instance, the model object that is created by JAXB has properties
such as:

@XmlElement(name = "encoded",namespace = "
http://purl.org/rss/1.0/modules/content/")
@JsonProperty("body")
public void setBody(String body)...

What appears to be happening is the json marshalling seems to be respecting
the element name from the @XmlElement annotation instead of the name given
in the @JsonProperty annotation.  In fact, it appears to ignore all @Json*
annotations for any property that has an @XmlElement annotation associated
with it.  So instead of "body": properties in my json I end up with
"encoded": properties

Has anyone else run into this?  It's pretty maddening :(

Thanks,

Craig

-- 
Craig Tataryn
site: http://www.basementcoders.com/
irc: ThaDon on freenode #basementcoders
twitter: craiger

Re: @XmlElement overriding @JsonProperty

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Did you look into this? Maybe there is a flag/option you can set in
jackson to have it favor @JsonProperty over JAXB. If so maybe there is
something we can add to camel-jackson, so you can turn this flag
on/off.

On Wed, Jul 17, 2013 at 11:57 PM, Craig Tataryn <cr...@tataryn.net> wrote:
> I'm working on a little route for my blog feed, essentially I have a route
> that looks like this:
>
> from("rss:...")
> .marshal().rss()
> .split(xpath("//item"))
> .unmarshal(jaxb)
> //do stuff to my Article object
> .marshal().json(JsonLibrary.Jackson)
>
> My problem is, when I marshal my model object to json I don't want it to
> have the same names as the element names from the XML the object was
> created from.
>
> So for instance, the model object that is created by JAXB has properties
> such as:
>
> @XmlElement(name = "encoded",namespace = "
> http://purl.org/rss/1.0/modules/content/")
> @JsonProperty("body")
> public void setBody(String body)...
>
> What appears to be happening is the json marshalling seems to be respecting
> the element name from the @XmlElement annotation instead of the name given
> in the @JsonProperty annotation.  In fact, it appears to ignore all @Json*
> annotations for any property that has an @XmlElement annotation associated
> with it.  So instead of "body": properties in my json I end up with
> "encoded": properties
>
> Has anyone else run into this?  It's pretty maddening :(
>
> Thanks,
>
> Craig
>
> --
> Craig Tataryn
> site: http://www.basementcoders.com/
> irc: ThaDon on freenode #basementcoders
> twitter: craiger



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen