0

I am using JAXB to marshall. I have noticed that when I am marshaling an object inside another object, the method for the inner object (for example: object A has a field of type B. Object B has a getter for a String) - this method is called twice (the getter for the String). Once for checking if not null (via hasValue method) and another time for getting the actual value (via writeLeafElememnt).

This seems awfully inefficient. Any thoughts on how to bypass this functionality?

Thank you very much.

1
  • Which implementation of JAXB (JSR-222) are you using: Metro (the reference implementation), EclipseLink MOXy, Apache JaxMe? Commented Jan 30, 2012 at 14:53

1 Answer 1

1

Firstly, if all the getter method is doing is returning a field value, then it has almost zero performance impact. The JVM is extremely good at optimising this sort of thing.

If you really want to avoid it, though, you can annotate the fields directly, rather than annotating the getter methods. It won't make any difference to the performance, though.

This is a classic example of premature micro-optimization. If you think something is slow, then measure it. If it's a performance hotspot then, and only then, do something about it.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.