Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] MOXy: mapping constant values?

Hi Polly,

EclipseLink handles read-only mappings, but not really write-only mappings. The easiest thing to do here would be to set up a mapping for your constant value using method-access. Then in the getter you can just return your constant value, and in the setter you can do nothing. For example:

public String getMyConstant() {
 return "My Constant String";
}

public void setMyConstant() {
 //do nothing
}

When using method access for a mapping it's not required by the runtime that the variable actually exist on the class, but you may need to add the instance variable in order to create the mapping in the workbench.

A couple of updates about other issues you were seeing:
The default namespace issue has been fixed in the runtime, so you no longer need a prefix for each namespace. You can now set a default namespace on a NamespaceResolver. There's a separate bug that has been created for Workbench support (236491).

The bug about error handling in JAXBContext (236525) is being looked at now.

Hope this helps,

-Matt

amphoras wrote:

Hi,

The situation I have is that there are some constant values that I want to
appear in my XML output document (like application=Foo).  I don't want this
value to be affected by unmarshalling.  How does one map this kind of
"constant"?

After playing around with EclipseLink, it looks like even though this value
is supposed to be a constant, I need to create a variable for it in my
domain object in order to create a mapping to the proper XPath.  But then
what should I do?  I don't want this variable's value to change by
unmarshalling.  I can write an afterLoad method to reset the variable back
to its original value.  That way when I marshall the object, the correct
value will be output in the XML. But is there a better way to do this? Does EclipseLink support one-way mappings or marshalling constants?

Thanks!
--Polly


Back to the top