解析生成JSON從RC-1升級到RC-3的JSON.stringfy()
方法後,在各值的開始和結束時返回與\
值:爪哇不能通過JSON.stringfy
{
\"perfil\":\"CLIENTE\", ...
}
我應該如何修復?
代碼片段:
post(url, data) {
console.log(JSON.stringify(data));
return Observable.create(observer =>
this.http.post(this.restConfig.baseUrl + url, JSON.stringify(data), {
headers: this.getDefaultHeaders()
}).subscribe(
data => this.next(observer, data)
, err => {
console.log(err);
if (err.status === 401) {
this.redirectAuth();
}
observer.error(err);
}
)
);
}
我的Java RESTful服務無法解析輸出:
Unexpected token (VALUE_STRING), expected FIELD_NAME: missing property 'perfil' that is to contain type id (for class br.com.inbit.medipop.model.entities.impl.Cliente) at [Source: [email protected]; line: 1, column: 1]
類Cliente:
@Table
@Entity
@DiscriminatorValue("CLIENTE")
public class Cliente extends Usuario {
}
類Usuario:
@Table
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "perfil", discriminatorType = DiscriminatorType.STRING)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "perfil")
@JsonSubTypes({
@JsonSubTypes.Type(value = Administrador.class, name = "ADMIN"),
@JsonSubTypes.Type(value = Colaborador.class, name = "COLABORADOR"),
@JsonSubTypes.Type(value = Parceiro.class, name = "PARCEIRO"),
@JsonSubTypes.Type(value = Cliente.class, name = "CLIENTE"),
@JsonSubTypes.Type(value = Dependente.class, name = "DEPENDENTE")
})
public abstract class Usuario {
@NotNull
@Enumerated(EnumType.STRING)
@Column(insertable = false, updatable = false)
protected PerfilUsuario perfil;
...
}
前
數據:
{"perfil":"CLIENTE","pessoa":{"tipo":"FISICA","sexo":"MASCULINO","nome":"Marcos Kichel","cpf":"911.111.064-36","rg":"1234"},"dependentes":[],"email":"[email protected]"}
請發佈您的代碼片段 – Apostolos
done @Apostolos :) –
這只是逃避報價。它實際上是造成問題嗎? – jonrsharpe