1

Bean:

@XmlRootElement(name = "integer") @XmlAccessorType(XmlAccessType.FIELD) public class IntegerWrapper implements Serializable { private static final long serialVersionUID = -455136597629446657L; @XmlValue private Integer value; // getters/setter (no annotations) } 

Code:

ObjectMapper mapper = new ObjectMapper(); IntegerWrapper iw = new IntegerWrapper(); iw.setValue(new Integer(11)); System.out.println("IntegerWrapper\n" + mapper.writeValueAsString(iw)); 

Result:

{"value":11,"fieldHandler":null} 

Why is "fieldHandler" in the resulting object, and how do I get rid of it?

UPDATE:

Appears only when I run it through maven or as a web service where Jackson is the JSON provider. IntegerWrapper is in the package where are some JPA beans but IntegerWrapper is not mentioned in persistence.xml. When I copy it to another package fieldHandler disappears.

4
  • 1
    No. Jackson wont add any such field. Does your IntegerWrapper has such a field? Commented Jul 22, 2014 at 13:58
  • No. IntegerWrapper has only one field 'value' and nothing more. Commented Jul 22, 2014 at 13:59
  • Is IntegerWrapper a JPA/Hibernate managed Object? Commented Jul 22, 2014 at 14:18
  • No is not any kind of proxy. Commented Jul 22, 2014 at 14:26

1 Answer 1

1

I searched for fieldHandler and it looks to be related to hibernate, I suspect that your object is managed by hibernate.

I had a quick look and I found jackson-datatype-hibernate perhaps this can be used to register a jackson module to get the results you desire.

Sign up to request clarification or add additional context in comments.

6 Comments

it is not specified in the persistence.xml file as a bean but.. it is in the package where are some beans. I will try to change the package to something else and we will see :P I run my test case as a jUnit by using maven.
@MarekRaszewski hopefully that's it. I was pretty sure it was gonna be the reason :)
if I copy something to my folder with beans .. "fieldHandler":null appears .. haha why ? :) I also try to run it normally as a jUnit (without maven) and fieldHandler does not appear. How to explain this behavior? What is the difference between jUnit run from eclipse and maven test
Are you scanning a package to detect your entities? If you are using spring for example it looks like this <context:component-scan base-package="foo.bar"/>
Ok, I have found the reason. You were very close. It was not mentioned in peristence.xml ...but the package containing beans was on the list for instrumentation in maven haha so xxx.bean.webservices.IntegerWrapper was also on the list :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.