本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.addMixInAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.addMixInAnnotations方法的具体用法?Java ObjectMapper.addMixInAnnotations怎么用?Java ObjectMapper.addMixInAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.addMixInAnnotations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialize
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testSerialize() throws Exception {
String expected = "{\"version\":null,\"status\":0,\"routeInstructions\":null,\"routeGeometry\":[[50.753,5.712],[50.653,6.012]]}";
GeoCoordinates[] coords = new GeoCoordinates[2];
coords[0] = new GeoCoordinates(50.753, 5.712);
coords[1] = new GeoCoordinates(50.653, 6.012);
PathData pathData = new PathData.Builder().withRouteGeometry(coords).build();
ObjectMapper mapper = new ObjectMapper();
mapper.addMixInAnnotations(PathData.class, UraPathDataMixIn.class);
Writer stringWriter = new StringWriter();
try {
mapper.writeValue(stringWriter, pathData);
String json = stringWriter.toString();
assertNotNull(json);
assertEquals(json, expected);
} catch (Exception e) {
fail();
}
}
示例2: testModalTypeSerialization
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testModalTypeSerialization() {
String expected = "{\"type\":\"IndividualTrip\",\"uuid\":null,\"start\":null,\"end\":null,\"status\":null," +
"\"lengthInM\":0.0,\"messageList\":null,\"modalType\":\"walk\",\"isAccessible\":null," +
"\"ticketMatches\":null,\"pathDataSource\":null,\"pathData\":null,\"durationInS\":null}";
IndividualTrip trip = new IndividualTrip.Builder().withModalType(ModalType.walk).build();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
mapper.addMixInAnnotations(IndividualTrip.class, UraIndividualTripMixIn.class);
Writer stringWriter = new StringWriter();
try {
mapper.writeValue(stringWriter, trip);
String json = stringWriter.toString();
assertNotNull(json);
assertEquals(json, expected);
} catch (Exception e) {
fail();
}
}