| XmlReadTransformer only for a read-only mapping [message #955136] |
Tue, 23 October 2012 10:44  |
Michal Politowski Messages: 2 Registered: October 2012 |
Junior Member |
|
|
I was under the impression that this should be possible.
XmlWriteTransformer javadoc seems to say that it is not needed for read-only mappings.
And there are even some tests for it in org/eclipse/persistence/testing/oxm/readonly/TransformationMappingTestCases.java
although these seem to be targeted at a different API level.
But with the following basic class:
package mpol.moxy;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlReadTransformer;
@XmlRootElement
public class Transformed {
@XmlReadTransformer(transformerClass=StringTransformer.class)
public String propA;
}
and the following simple transformer:
package mpol.moxy;
import org.eclipse.persistence.mappings.foundation.AbstractTransformationMapping;
import org.eclipse.persistence.mappings.transformers.AttributeTransformer;
import org.eclipse.persistence.sessions.Record;
import org.eclipse.persistence.sessions.Session;
@SuppressWarnings("serial")
public class StringTransformer implements AttributeTransformer {
@Override
public void initialize(AbstractTransformationMapping mapping) {}
@Override
public Object buildAttributeValue(Record record, Object object, Session session) {
String value = (String) record.get("A_PROP");
return value!=null?value.toUpperCase():null;
}
}
the following code fails with NPE, because record is null in buildAttributeValue:
unmarshaller.unmarshal(new StringReader("<transformed><A_PROP>a</A_PROP></transformed>"));
Is it a MOXy bug, or do I need to do something more to make this work?
--
MichaĆ Politowski
|
|
|