Ecco il mio codice Java che viene utilizzato per la de-serializzazione, sto cercando di convertire la stringa json in oggetto java. In tal modo ho usato il seguente codice:dessonializzazione di jackson json a java-objects
package ex1jackson;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
public class Ex1jackson {
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
try {
String userDataJSON = "[{\"id\":\"value11\",\"name\": \"value12\",\"qty\":\"value13\"},"
+ "{\"id\": \"value21\",\"name\":\"value22\",\"qty\": \"value23\"}]";
product userFromJSON = mapper.readValue(userDataJSON, product.class);
System.out.println(userFromJSON);
} catch (JsonGenerationException e) {
System.out.println(e);
} catch (JsonMappingException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
}
}
}
e la mia classe product.java
package ex1jackson;
public class product
{
private String id;
private String name;
private String qty;
@Override
public String toString() {
return "Product [id=" + id+ ", name= " + name+",qty="+qty+"]";
}
}
sto ottenendo il seguente errore.
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "id" (class ex1jackson.product), not marked as ignorable (0 known properties: ]) at
[Source: [email protected]; line: 1, column: 8] (through reference chain: ex1jackson.product["id"])
BUILD SUCCESSFUL (total time: 0 seconds)
aiutarmi a risolvere questo,
@ Esteban Araya ho provato questo stesso errore si verifica – MAHI