मेरे संस्था के साथ deserialize json:अशक्त आईडी संपत्ति जब जैक्सन और वसंत के Jackson2HalModule Hateoas
public class User {
private Integer id;
private String mail;
private boolean enabled;
// getters and setters
}
फ़ाइल test.json (बाकी वेब सेवा से प्रतिक्रिया):
{
"_embedded" : {
"users" : [ {
"id" : 1,
"mail" : "[email protected]",
"enabled" : true,
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/users/1"
}
}
} ]
}
}
और अपने परीक्षण वर्ग:
public class TestJson {
private InputStream is;
private ObjectMapper mapper;
@Before
public void before() {
mapper = new ObjectMapper();
mapper.registerModule(new Jackson2HalModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
is = TestJson.class.getResourceAsStream("/test.json");
}
@After
public void after() throws IOException {
is.close();
}
@Test
public void test() throws IOException {
PagedResources<Resource<User>> paged = mapper.readValue(is, new TypeReference<PagedResources<Resource<User>>>() {});
Assert.assertNotNull(paged.getContent().iterator().next().getContent().getId());
}
@Test
public void testResource() throws IOException {
PagedResources<User> paged = mapper.readValue(is, new TypeReference<PagedResources<User>>() {});
Assert.assertNotNull(paged.getContent().iterator().next().getId());
}
}
दूसरा परीक्षण गुजरता है लेकिन पहले नहीं। मुझे समझ में नहीं आ रहा है क्योंकि उपयोगकर्ता में आईडी संपत्ति केवल एक गायब है (मेल और सक्षम गुण खाली नहीं हैं) ...
इसे ठीक करने के लिए मुझे क्या करना है? क्या यह जैक्सन या स्प्रिंग जैक्सन 2 हैल मॉड्यूल में एक बग है?
आप मेरे वसंत-नफरत फोर्क repository क्लोनिंग और यूनिट परीक्षण लॉन्च करके पुन: पेश कर सकते हैं।
'वसंत-hateoas' और' वसंत-boot' साथ एक ही समस्या है, इसलिए मैं किसी और – cahen
हैं कुछ करने के लिए 'id' नाम बदलने के लिए किया था आपको यकीन है कि यह काम करता है? – Gazeciarz
यह एक साल पहले था, लेकिन अगर मुझे सही याद है, तो यह वास्तव में एक संकलन त्रुटि के कारण काम नहीं करता है जो मुझे लगता है ... मुझे मिला एकमात्र समाधान कैहेन है। आपको अपनी आईडी संपत्ति का नाम किसी अन्य चीज़ में बदलना होगा। – mfalaize