У меня есть Json строка "{"value":"3A72fd4ccb-1980-26cf-8db3-9eaadf1205c2"}"
, при передаче той же строки в приведенный ниже код:
Gson headerGson = new GsonBuilder().create();
Object ob = headerGson.fromJson(jsonStr, cl);
Результирующий объект не получает присвоено "значение" является json строка , Когда я попытался напечатать поле объекта с помощью ReflectionAPI, я получил: Поля: значение Соответствующий тип поля -> класс java .lang.String Соответствующее значение -> ноль
Класс java что я передал как "cl" в методе from Json, как показано ниже:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AttributedURI", propOrder = {
"value"
})
public class AttributedURI {
@XmlValue
@XmlSchemaType(name = "anyURI")
protected String value;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* 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;
}
/**
* Gets a map that contains attributes that aren't bound to any typed property on this class.
*
* <p>
* the map is keyed by the name of the attribute and
* the value is the string value of the attribute.
*
* the map returned by this method is live, and you can add new attribute
* by updating the map directly. Because of this design, there's no setter.
*
*
* @return
* always non-null
*/
public Map<QName, String> getOtherAttributes() {
return otherAttributes;
}
}
Пожалуйста, дайте мне знать, что мне здесь не хватает.