Object must have some value in its @XmlValue field

user4499364

I have the following code

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "udt_TextType", propOrder = { "value" })
@XmlSeeAlso({ RoadTypeCodeTypeType.class })
public class UdtTextType {

@XmlValue
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
@XmlSchemaType(name = "normalizedString")
protected String value;

/**
 * Gets the value of the value property.
 * 
 * @return possible object is {@link String }
 * 
 */
public String getValue() {
    return value;
}

/**
 * Sets the value of the value property.
 * 
 * @param value
 *            allowed object is {@link String }
 * 
 */
public void setValue(String value) {
    this.value = value;
}

When I try to marshall this object:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AdresseCompleteType", propOrder = { "inHouseMail", "buildingName", "buildingNumber", "blockName", "roadType",
        "streetName", "postcode", "cityName", "lineFive" })
public class AdresseCompleteType {

    @XmlElement(name = "InHouseMail")
    protected UdtTextType inHouseMail;
    @XmlElement(name = "BuildingName")
    protected UdtTextType buildingName;
    @XmlElement(name = "BuildingNumber")
    protected UdtTextType buildingNumber;
    ...

I have the following error: Object must have some value in its @XmlValue field

Why do I get this error?

com.sun.xml.internal.bind.api.AccessorException: Object must have some value in its @XmlValue field: fr.company.jaxb.UdtTextType@17f2dd8] at 
    fr.company.Service.launchXML(Service.java:303) at 
    fr.company.Service.launchZIP(Service.java:370) at 
    fr.company.MainTest.testGenerationZip(MainTest.java:17) at 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57))

Thanks!

bdoughan

The following explains why you are getting the exception:

Java Model

Below is a simplified version of your model that demonstrates the problem:

UdtTextType

This class has a field annotated with @XmlValue:

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
public class UdtTextType {

    @XmlValue
    protected String value;

    public void setValue(String value) {
        this.value = value;
    }

}

AdreseCompleteType

The important thing to note is that inHouseMail field is a type that has a mapping with @XmlValue.

import javax.xml.bind.annotation.*;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AdreseCompleteType {

    @XmlElement(name = "InHouseMail")
    protected UdtTextType inHouseMail;

    public void setInHouseMail(UdtTextType inHouseMail) {
        this.inHouseMail = inHouseMail;
    }

}

XML Representation

Lets examine the different XML representations that can arise from the object model.

#1 - inHouseMail Property is null

AdreseCompleteType adreseCompleteType = new AdreseCompleteType();
adreseCompleteType.setInHouseMail(null);

In the XML representation the inHouseMail field is should as null my not including that element in the resulting XML.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<adreseCompleteType/>

#2 - inHouseMail Property is set and UdtTextType has a Value

UdtTextType udtTextType = new UdtTextType();
udtTextType.setValue("Hello World");

AdreseCompleteType adreseCompleteType = new AdreseCompleteType();
adreseCompleteType.setInHouseMail(udtTextType);

Since the inHouseMail field is set we get the InHouseMail element, and since its value field is populated that is output as well.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<adreseCompleteType>
    <InHouseMail>Hello World</InHouseMail>
</adreseCompleteType>

#3 - inHouseMail Property is set and UdtTextType has a Empty String Value

UdtTextType udtTextType = new UdtTextType();
udtTextType.setValue("");

AdreseCompleteType adreseCompleteType = new AdreseCompleteType();
adreseCompleteType.setInHouseMail(udtTextType);

Since the inHouseMail field is set we get the InHouseMail element, and since its value field is populated as an empty String that is output as an empty element.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<adreseCompleteType>
    <InHouseMail></InHouseMail>
</adreseCompleteType>

#4 - inHouseMail Property is set and UdtTextType has a null Value

UdtTextType udtTextType = new UdtTextType();
udtTextType.setValue(null);

AdreseCompleteType adreseCompleteType = new AdreseCompleteType();
adreseCompleteType.setInHouseMail(udtTextType);

The problem is what should this XML look like. It can't be an empty element like #3 since JAXB (and XML) does not represent null as an empty element. It also can't be represented as a missing InHouseMail element as that would conflict with scenario #1. So the following exception is thrown:

Exception in thread "main" javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: Object must have some value in its @XmlValue field: forum28411016.UdtTextType@f7ca0f5
com.sun.xml.internal.bind.api.AccessorException: Object must have some value in its @XmlValue field: forum28411016.UdtTextType@f7ca0f5]
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
    at forum28411016.Demo.main(Demo.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: com.sun.istack.internal.SAXException2: Object must have some value in its @XmlValue field: forum28411016.UdtTextType@f7ca0f5
com.sun.xml.internal.bind.api.AccessorException: Object must have some value in its @XmlValue field: forum28411016.UdtTextType@f7ca0f5
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:235)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:250)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:347)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:582)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:325)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:483)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
    ... 8 more
Caused by: com.sun.xml.internal.bind.api.AccessorException: Object must have some value in its @XmlValue field: forum28411016.UdtTextType@f7ca0f5
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeClassInfoImpl$TransducerImpl.writeLeafElement(RuntimeClassInfoImpl.java:395)
    at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.writeLeafElement(TransducedAccessor.java:239)
    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:114)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:343)
    ... 12 more

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Linq: Nullable Object must have Value

From Dev

Nullable object must have a value datetime

From Dev

Decimal? - Nullable object must have a value

From Dev

field 'FIELD' is never assigned to, and will always have its default value

From Dev

Select value if its row have some value excel

From Dev

Field modifyDate is never assigned to, and will always have its default value 0

From Dev

Serializing object in Jackson and @XmlValue

From Dev

"Nullable object must have a value" when Where uses a method?

From Dev

best method to solve Nullable object must have a value in datetime

From Dev

Nullable object must have a value. VB.NET

From Dev

Anonymous Type "Nullable object must have a value" Error

From Dev

Yii 2 Field 2 must have greater value than Field 1

From Dev

Why does every object of this class have the same value for its members?

From Dev

Why does every object of this class have the same value for its members?

From Dev

Why does a function value of an object not have its own scope?

From Dev

Order by field and its value

From Java

The field "$name" must be an accumulator object

From Dev

"Nullable object must have a value" exception after checking for null on a non-primitive/non-struct object

From Dev

Field is never assigned to, and will always have its default value null (CS0649)

From Dev

Struct in c# giving warning Field is never assigned to,and will always have its default value0

From Dev

Struct in c# giving warning Field is never assigned to,and will always have its default value0

From Dev

ASP.NET MVC 5 Razor throws 'Nullable object must have a value' even when the object has value

From Dev

Abstract type Node must resolve to an Object type at runtime for field Root.node with value \"\",received \"null\"."

From Dev

Delete a hidden field by its value

From Dev

Stripe error: "The card object must have a value for 'number'" when creating a Customer

From Dev

Nullable object must have a value while using datepicker control with dropdown control

From Dev

when using Action as a property (instead of a Field), calling the method causes error: Property access must assign to the property or use its value

From Dev

ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object

From Dev

ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object

Related Related

  1. 1

    Linq: Nullable Object must have Value

  2. 2

    Nullable object must have a value datetime

  3. 3

    Decimal? - Nullable object must have a value

  4. 4

    field 'FIELD' is never assigned to, and will always have its default value

  5. 5

    Select value if its row have some value excel

  6. 6

    Field modifyDate is never assigned to, and will always have its default value 0

  7. 7

    Serializing object in Jackson and @XmlValue

  8. 8

    "Nullable object must have a value" when Where uses a method?

  9. 9

    best method to solve Nullable object must have a value in datetime

  10. 10

    Nullable object must have a value. VB.NET

  11. 11

    Anonymous Type "Nullable object must have a value" Error

  12. 12

    Yii 2 Field 2 must have greater value than Field 1

  13. 13

    Why does every object of this class have the same value for its members?

  14. 14

    Why does every object of this class have the same value for its members?

  15. 15

    Why does a function value of an object not have its own scope?

  16. 16

    Order by field and its value

  17. 17

    The field "$name" must be an accumulator object

  18. 18

    "Nullable object must have a value" exception after checking for null on a non-primitive/non-struct object

  19. 19

    Field is never assigned to, and will always have its default value null (CS0649)

  20. 20

    Struct in c# giving warning Field is never assigned to,and will always have its default value0

  21. 21

    Struct in c# giving warning Field is never assigned to,and will always have its default value0

  22. 22

    ASP.NET MVC 5 Razor throws 'Nullable object must have a value' even when the object has value

  23. 23

    Abstract type Node must resolve to an Object type at runtime for field Root.node with value \"\",received \"null\"."

  24. 24

    Delete a hidden field by its value

  25. 25

    Stripe error: "The card object must have a value for 'number'" when creating a Customer

  26. 26

    Nullable object must have a value while using datepicker control with dropdown control

  27. 27

    when using Action as a property (instead of a Field), calling the method causes error: Property access must assign to the property or use its value

  28. 28

    ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object

  29. 29

    ReactCompositeComponent.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object

HotTag

Archive