すべてのフィールドがあります。ジャクソンのJava EE WS - XMLが空ですが、JSONは私がRESTサービスで露光てるPOJOを持って
@XmlRootElement
public class Field implements Serializable{
/**
*
*/
@JsonIgnore
private static final long serialVersionUID = 1L;
FieldType fieldType;
String name;
Object deafultValue;
Map<String, String> choices;
boolean required;
public Field(){}
@JsonCreator
public Field(@JsonProperty("fieldType") FieldType fieldType, String name, Object deafultValue, Map<String, String> choices, boolean required) {
super();
this.fieldType = fieldType;
this.name = name;
this.deafultValue = deafultValue;
this.choices = choices;
this.required = required;
}
@JsonProperty
public FieldType getFieldType() {
return fieldType;
}
@Override
public String toString() {
return "Field [fieldType=" + fieldType + ", name=" + name + ", deafultValue=" + deafultValue + ", choices="
+ choices + ", required=" + required + "]";
}
public String getName() {
return name;
}
public Object getDeafultValue() {
return deafultValue;
}
public Map<String, String> getChoices() {
return choices;
}
public boolean isRequired() {
return required;
}
}
私が露出されているオブジェクトの数を持っているが、ほとんどのそれらは@Entity
注釈でマークされており、正常に動作します。ここで
は私のWebサービスのコードです:
@GET
@Path("search-fields")
@Produces({"application/xml", "application/json"})
public List<Field> getSearchFields(){
L.debug("Getting Actor search fields: {}", new Actor().getSearchFields());
return new Actor().getSearchFields();
}
ログメッセージは、データがあることを言う:
DEBUG ActorsFacadeREST - 俳優の検索フィールドを取得:[フィールド[FIELDTYPE = INPUT 、name = Name、deafultValue = null、choices = null、required = true]]
私はJSONを照会:
$ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/actor-service/webresources/entities.actors/search-fields/ && echo ""
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/10
Content-Type: application/json
Content-Length: 88
Date: Sun, 20 Mar 2016 13:44:46 GMT
[{"fieldType":"INPUT","name":"Name","deafultValue":null,"choices":null,"required":true}]
私はXMLを求める:
$ curl -i -H "Accept: application/xml" -H "Content-Type: application/json" -X GET http://localhost:8080/actor-service/webresources/entities.actors/search-fields/ && echo ""
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/10
Content-Type: application/xml
Content-Length: 88
Date: Sun, 20 Mar 2016 13:46:47 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><collection><field/></collection>
はなぜJSONオブジェクトのデータを持っていないが、XMLは空ですか? @XmlRootElement
以外のXMLアノテーション(私には見つからない)がありますか?
私は正常に動作する、以下の豆持って
を追加するように編集:私はあなたにも@XmlElementであなたのフィールドに注釈を付けるために持っていると思う
public class Actor implements Serializable, HasImage, Searchable<Actor> {
private static final transient Logger L = LoggerFactory.getLogger(Actor.class);
private static final long serialVersionUID = 1L;
private Long id;
private String eid;
private String name;
private String status;
private String reportsToEid;
private String email;
String imageLocation;
PathType pathType;
public Actor() {
L.debug("Actor created with default constructor");
}
@JsonCreator
public Actor(@JsonProperty("id") Long id, @JsonProperty("eid") String eid, @JsonProperty("name")String name,
@JsonProperty("status") String status, @JsonProperty("reportsToId") String reportsToEid,
@JsonProperty("email") String email, @JsonProperty("imageLocation")String imageLocation,
@JsonProperty("pathType") PathType pathType) {
super();
L.debug("Actor created with JsonCreator marked constructor");
this.id = id;
this.eid = eid;
this.name = name;
this.status = status;
this.reportsToEid = reportsToEid;
this.email = email;
this.imageLocation = imageLocation;
this.pathType = pathType;
}
OK、私は作業オブジェクトを投稿しました(上記の私の編集で)。なぜそれが必要なのですか? – mikeb