Search in sources :

Example 1 with SerializationConfig

use of org.codehaus.jackson.map.SerializationConfig in project camunda-bpm-platform by camunda.

the class JsonUtil method getMapper.

public static ObjectMapper getMapper() {
    if (mapper == null) {
        mapper = new ObjectMapper();
        SerializationConfig config = mapper.getSerializationConfig().withSerializationInclusion(Inclusion.NON_EMPTY).without(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        mapper.setSerializationConfig(config);
    }
    return mapper;
}
Also used : SerializationConfig(org.codehaus.jackson.map.SerializationConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with SerializationConfig

use of org.codehaus.jackson.map.SerializationConfig in project helix by apache.

the class TestHelixAdminScenariosRest method ObjectToJson.

public static String ObjectToJson(Object object) throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, object);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with SerializationConfig

use of org.codehaus.jackson.map.SerializationConfig in project helix by apache.

the class ClusterRepresentationUtil method ObjectToJson.

public static String ObjectToJson(Object object) throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, object);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with SerializationConfig

use of org.codehaus.jackson.map.SerializationConfig in project helix by apache.

the class ResourceUtil method objectToJson.

private static String objectToJson(Object object) {
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    try {
        mapper.writeValue(sw, object);
    } catch (JsonGenerationException e) {
    // Should not be here
    } catch (JsonMappingException e) {
    // Should not be here
    } catch (IOException e) {
    // Should not be here
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with SerializationConfig

use of org.codehaus.jackson.map.SerializationConfig in project helix by apache.

the class TestSchedulerMessage method testSchedulerZeroMsg.

@Test
public void testSchedulerZeroMsg() throws Exception {
    _factory._results.clear();
    HelixManager manager = null;
    for (int i = 0; i < NODE_NR; i++) {
        _participants[i].getMessagingService().registerMessageHandlerFactory(_factory.getMessageTypes(), _factory);
        // _startCMResultMap.get(hostDest)._manager;
        manager = _participants[i];
    }
    Message schedulerMessage = new Message(MessageType.SCHEDULER_MSG + "", UUID.randomUUID().toString());
    schedulerMessage.setTgtSessionId("*");
    schedulerMessage.setTgtName("CONTROLLER");
    // TODO: change it to "ADMIN" ?
    schedulerMessage.setSrcName("CONTROLLER");
    // Template for the individual message sent to each participant
    Message msg = new Message(_factory.getMessageTypes().get(0), "Template");
    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    // Criteria to send individual messages
    Criteria cr = new Criteria();
    cr.setInstanceName("localhost_DOESNOTEXIST");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setResource("%");
    cr.setPartition("%");
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, cr);
    String crString = sw.toString();
    schedulerMessage.getRecord().setSimpleField("Criteria", crString);
    schedulerMessage.getRecord().setMapField("MessageTemplate", msg.getRecord().getSimpleFields());
    schedulerMessage.getRecord().setSimpleField("TIMEOUT", "-1");
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    PropertyKey controllerMessageKey = keyBuilder.controllerMessage(schedulerMessage.getMsgId());
    helixDataAccessor.setProperty(controllerMessageKey, schedulerMessage);
    Thread.sleep(3000);
    Assert.assertEquals(0, _factory._results.size());
    PropertyKey controllerTaskStatus = keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(), schedulerMessage.getMsgId());
    for (int i = 0; i < 10; i++) {
        StatusUpdate update = helixDataAccessor.getProperty(controllerTaskStatus);
        if (update == null || update.getRecord().getMapField("SentMessageCount") == null) {
            Thread.sleep(1000);
        }
    }
    ZNRecord statusUpdate = helixDataAccessor.getProperty(controllerTaskStatus).getRecord();
    Assert.assertTrue(statusUpdate.getMapField("SentMessageCount").get("MessageCount").equals("0"));
    int count = 0;
    for (Set<String> val : _factory._results.values()) {
        count += val.size();
    }
    Assert.assertEquals(count, 0);
}
Also used : HelixManager(org.apache.helix.HelixManager) Message(org.apache.helix.model.Message) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) Criteria(org.apache.helix.Criteria) StatusUpdate(org.apache.helix.model.StatusUpdate) HelixDataAccessor(org.apache.helix.HelixDataAccessor) StringWriter(java.io.StringWriter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PropertyKey(org.apache.helix.PropertyKey) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Aggregations

SerializationConfig (org.codehaus.jackson.map.SerializationConfig)19 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)16 StringWriter (java.io.StringWriter)13 ZNRecord (org.apache.helix.ZNRecord)8 Criteria (org.apache.helix.Criteria)7 HelixDataAccessor (org.apache.helix.HelixDataAccessor)7 HelixManager (org.apache.helix.HelixManager)7 PropertyKey (org.apache.helix.PropertyKey)7 Message (org.apache.helix.model.Message)7 Test (org.testng.annotations.Test)7 Builder (org.apache.helix.PropertyKey.Builder)4 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)4 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)4 HelixException (org.apache.helix.HelixException)3 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 ConstraintItem (org.apache.helix.model.ConstraintItem)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 DeserializationConfig (org.codehaus.jackson.map.DeserializationConfig)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1