내가 자바 객체 (위치 클래스)에 JSON 객체 다음 desalinize 할 :JSON은 객체 직렬화
public class Location{
@ManyToOne
@ForeignKey(name = "FK_location__organization")
private Organization organization;
@NotNull
@Column(nullable = false)
private String name;
private boolean disabled;
private String street;
private String postalCode;
private String city;
private String country;
private Double latitude;
private Double longitude;
@Override
public String toString()
{
return name;
}
public static List<Location> findAllLocationsOrderedByName()
{
return entityManager().createQuery("SELECT o FROM Location o ORDER BY name ASC", Location.class).getResultList();}}
그리고 조직 클래스는 다음과 같습니다 :
{
"city": "TEST",
"country": "TEST",
"latitude": "1",
"longitude": "1",
"name": "TEST",
"postalCode": "362001",
"street": "TEST",
"organization": 3
}
내 자바 클래스이다
public class Organization {
String name
}
deserialize 할 때 다음 오류가 발생했습니다.
(210)flexjson.JsonNumber cannot be cast to java.util.Map
flexjson.factories.BeanObjectFactory.instantiate(BeanObjectFactory.java:17)
flexjson.ObjectBinder.bind(ObjectBinder.java:95)
flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:149)
flexjson.ObjectBinder.bind(ObjectBinder.java:95)
flexjson.ObjectBinder.bind(ObjectBinder.java:74)
flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:158)
flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:38)
나는 역 직렬화에 대한 코드 (플렉스 JSON을 사용하여) 다음 사용
import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
public static Location Location.fromJsonToLocation(String json) {
System.out.println(json);
return new JSONDeserializer<Location>()
.use(null, Location.class).deserialize(json);
}
그래서? 질문이 뭐야? –
Java 클래스에 Json 객체를 비 직렬화하고 싶습니다. 다음 오류가 발생했습니다. flexjson.JsonNumber를 java.util.Map으로 캐스팅 할 수 없습니다. flexjson.factories.BeanObjectFactory.instantiate (BeanObjectFactory.java:17) flexjson.ObjectBinder.bind (ObjectBinder.java:95) flexjson.ObjectBinder.bindIntoObject (ObjectBinder.java:149) flexjson.factories.ClassLocatorObjectFactory.instantiate (ClassLocatorObjectFactory.java:38) flexjson.ObjectBinder.bind (ObjectBinder. (JSONDeserializer.java:158) – Devloper
이 오류로 질문을 업데이트하십시오. 또한 JSON을 구문 분석 할 때 사용하는 도구를 추가하십시오. – mvg