当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.registerModule方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.registerModule方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.registerModule方法的具体用法?Java ObjectMapper.registerModule怎么用?Java ObjectMapper.registerModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.registerModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSystemEvent

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private String createSystemEvent(String tenant, String command) {
    SystemEvent event = new SystemEvent();
    event.setEventId(MDCUtil.getRid());
    event.setEventType(command);
    event.setTenantInfo(TenantContext.getCurrent());
    event.setMessageSource(appName);
    event.getData().put(Constants.EVENT_TENANT, tenant);
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    try {
        return mapper.writeValueAsString(event);
    } catch (JsonProcessingException e) {
        log.error("System Event mapping error", e);
        throw new BusinessException("Event mapping error", e.getMessage());
    }

}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:18,代码来源:KafkaService.java

示例2: write

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static void write(Contingency object, Path jsonFile) {
    Objects.requireNonNull(object);
    Objects.requireNonNull(jsonFile);

    try (OutputStream os = Files.newOutputStream(jsonFile)) {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
        mapper.registerModule(module);

        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        writer.writeValue(os, object);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:ContingencyJsonTest.java

示例3: 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();
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:20,代码来源:UraModalTypeWrapperTest.java

示例4: createObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static ObjectMapper createObjectMapper() {

        ObjectMapper mapper = new ObjectMapper();

        mapper.registerModule(new Jdk8Module());
        mapper.registerModule(new JavaTimeModule());
        mapper.registerModule(new ParameterNamesModule());

        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

        return mapper;
    }
 
开发者ID:cassiomolin,项目名称:jersey-jwt,代码行数:18,代码来源:ObjectMapperProvider.java

示例5: toJSONString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Produces a string containing a JSON representation of the object. The
 * default implementation just falls back to Jackson Java 8 serialization
 * 
 * @return A {@code String} containing JSON
 */
public default String toJSONString() {
    try {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new Jdk8Module());
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException jsonx) {
        throw new RuntimeException(jsonx);
    }
}
 
开发者ID:hazelcast,项目名称:betleopard,代码行数:16,代码来源:JSONSerializable.java

示例6: initObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void initObjectMapper(CrnkFeature feature) {
	ObjectMapper objectMapper = feature.getObjectMapper();
	objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
	objectMapper.registerModule(new JavaTimeModule());
	objectMapper.findAndRegisterModules();
	objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:8,代码来源:ApprovalTestApplication.java

示例7: parse

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Generic helper method that takes a string and a mapping function
 * 
 * @param <E>       The desired output type
 * @param parseText The input data to be parsed
 * @param fn        A {@code Function} object to take a string bag and produce an instance of {@code E}
 * @return          An instance of {@code E}
 */
public static <E> E parse(final String parseText, final Function<Map<String, ?>, E> fn) {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    try {
        return fn.apply(mapper.readValue(parseText, new TypeReference<Map<String, ?>>() {
        }));
    } catch (IOException iox) {
        throw new RuntimeException(iox);
    }
}
 
开发者ID:hazelcast,项目名称:betleopard,代码行数:19,代码来源:JSONSerializable.java

示例8: benchSetup

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) {
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(new AfterburnerModule());
    typeReference = new TypeReference<TestObject>() {
    };
    testJSON = TestObject.createTestJSON();
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:9,代码来源:DeserJackson.java

示例9: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
开发者ID:mraible,项目名称:devoxxus-jhipster-microservices-demo,代码行数:19,代码来源:TestUtil.java

示例10: customObjectMapperForSpring

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Example how skip auto-configuration and use a custom ObjectMapper.
 * Also can use a Jackson2ObjectMapperBuilder bean for the same purpose.
 */
//@Bean
ObjectMapper customObjectMapperForSpring() {
	ObjectMapper mapper = new ObjectMapper();
	JavaTimeModule javaTimeModule = new JavaTimeModule();
	javaTimeModule.addSerializer(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("YYYY-MMM")));
	mapper.registerModule(javaTimeModule);
	mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
	mapper.setDateFormat(new SimpleDateFormat("YYYY"));
	return mapper;
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:15,代码来源:AppConfig.java

示例11: mappingJackson2HttpMessageConverter

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    objectMapper.registerModule(new Jackson2HalModule());
    jsonConverter.setObjectMapper(objectMapper);
    return jsonConverter;
}
 
开发者ID:pawankumar8608,项目名称:spring-cloud-microservices-docker,代码行数:12,代码来源:Application.java

示例12: NykreditJsonProvider

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public NykreditJsonProvider(ObjectMapper mapper) {
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new Jdk8Module());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
    setMapper(mapper);
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:10,代码来源:NykreditJsonProvider.java

示例13: camelToKebabObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private ObjectMapper camelToKebabObjectMapper(SimpleModule sm) {
    ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.setPropertyNamingStrategy(new CamelCaseToKebabCaseNamingStrategy());
    if (sm != null) {
        jsonMapper.registerModule(sm);
    }
    jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return jsonMapper;
}
 
开发者ID:zg2pro,项目名称:spring-rest-basis,代码行数:10,代码来源:AbstractZg2proRestTemplate.java

示例14: serializeAnnotatedType

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void serializeAnnotatedType() throws Exception {
    PersonGroup group = new PersonGroup(1L, "group1", "思考、距离、俘获", new ArrayList<Person>(), "距离产生美");
    Person p1 = new Person(1L, "chaokunyang", "男", 23, "快与慢", group);
    Person p2 = new Person(1L, "chaokunyang", "男", 23, "快与慢", group);
    group.getPersons().add(p1);
    group.getPersons().add(p2);


    SimpleModule module = new SimpleModule();
    Set<Class<?>> annotatedClasses = ClassUtils.getAnnotatedClasses("com.timeyang.search.entity", Document.class);
    annotatedClasses.forEach(aClass -> module.addSerializer(aClass, new JkesJsonSerializer<>()));

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    String groupResult = mapper.writeValueAsString(group); // 序列化

    assertThat(groupResult, containsString("group1"));
    assertNotEquals(groupResult, containsString("距离产生美"));
    assertNotEquals(groupResult, containsString("快与慢"));
    System.out.println(groupResult);

    String p1Result = mapper.writeValueAsString(p1); // 序列化
    assertNotEquals(p1Result, containsString("chaokunyang"));
    System.out.println(p1Result);

    String p2Result = mapper.writeValueAsString(p2); // 序列化
    assertNotEquals(p2Result, containsString("chaokunyang"));
    System.out.println(p2Result);
}
 
开发者ID:chaokunyang,项目名称:jkes,代码行数:33,代码来源:JkesJsonSerializerTest.java

示例15: LoadSaveString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public void LoadSaveString(String loadString) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        this.loadString = loadString;
        mapper.registerModule(module);
        //New instance of the JSONObject, being initialized, from the loadString
        JSONObject json = new JSONObject(loadString);
        //all the instances of rooms, and the player, which where serialized and saved in a file, gets read, as single objects, and their info, put into a string, containing only the that info
        String playerPart = json.getJSONObject("player").toString();
        String medbayPart = json.getJSONObject("Medbay").toString();
        String Hallway = json.getJSONObject("Hallway").toString();
        String Keyroom = json.getJSONObject("Keyroom").toString();
        String Communicationroom = json.getJSONObject("Communicationroom").toString();
        String Armoury = json.getJSONObject("Armoury").toString();
        String Airlock = json.getJSONObject("Airlock").toString();
        String Currentroom = json.getJSONObject("Currentroom").toString();
        
        //Here a new player1, gets initialized, from the string playerPart, and deserialized into a Player.class.
        Player player1 = mapper.readValue(playerPart, Player.class);
        
        //Here the Rooms get initialized from their respective strings, and deserialized, into the Room.class
        Room medbay = mapper.readValue(medbayPart, Room.class);
        Room Hallway1 = mapper.readValue(Hallway, Room.class);
        Room Keyroom1 = mapper.readValue(Keyroom, Room.class);
        Room Communicationroom1 = mapper.readValue(Communicationroom, Room.class);
        Room Armoury1 = mapper.readValue(Armoury, Room.class);
        Room Airlock1 = mapper.readValue(Airlock, Room.class);
        String Currentroom1 = mapper.readValue(Currentroom, Room.class).getName();
        
        //Here the deserialized player and rooms, get set into the game class, as the new player and rooms, with all the info, from when the user saved the game
        game.setPlayer(player1);
        game.setMedbay(medbay);
        game.setHallway(Hallway1);
        game.setKeyRoom(Keyroom1);
        game.setCommunicationRoom(Communicationroom1);
        game.setArmoury(Armoury1);
        game.setAirlock(Airlock1);
        game.setCurrentRoom(Currentroom1);

    } catch (JSONException | IOException ex) {
        Logger.getLogger(SaveFile.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:jolluguy,项目名称:World-of-Zuul-SDU,代码行数:45,代码来源:SaveFile.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.registerModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。