org.msgpack.jackson.dataformat.MessagePackFactory Java Examples
The following examples show how to use
org.msgpack.jackson.dataformat.MessagePackFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessagePackJsonConverter.java From konker-platform with Apache License 2.0 | 6 votes |
@Override public ServiceResponse<String> toJson(byte bytes[]) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { // read message pack ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); JsonNode node = objectMapper.readTree(bytes); // write json JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jsonGenerator = jsonFactory.createGenerator(bos); objectMapper.writeTree(jsonGenerator, node); } catch (IOException | NullPointerException e) { LOGGER.error("Exception converting message pack to JSON", e); return ServiceResponseBuilder.<String>error().build(); } return ServiceResponseBuilder.<String>ok().withResult(new String(bos.toByteArray())).build(); }
Example #2
Source File: MessagePackJsonConverter.java From konker-platform with Apache License 2.0 | 6 votes |
@Override public ServiceResponse<byte[]> fromJson(String json) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { // read json ObjectMapper objectMapper = new ObjectMapper(new JsonFactory()); JsonNode node = objectMapper.readTree(json); // write message pack MessagePackFactory messagePackFactory = new MessagePackFactory(); JsonGenerator jsonGenerator = messagePackFactory.createGenerator(bos); objectMapper.writeTree(jsonGenerator, node); } catch (IOException e) { LOGGER.error("Exception converting message pack to JSON", e); return ServiceResponseBuilder.<byte[]>error().build(); } return ServiceResponseBuilder.<byte[]>ok().withResult(bos.toByteArray()).build(); }
Example #3
Source File: MessagePackRecordFormatterTest.java From fluency with Apache License 2.0 | 6 votes |
private ByteBuffer convertMapToMessagePackByteBuffer(Map<String, Object> record, boolean isDirect) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); byte[] bytes = objectMapper.writeValueAsBytes(record); ByteBuffer byteBuffer; if (isDirect) { byteBuffer = ByteBuffer.allocateDirect(bytes.length); } else { byteBuffer = ByteBuffer.allocate(bytes.length); } byteBuffer.put(bytes); byteBuffer.flip(); return byteBuffer; }
Example #4
Source File: JsonlRecordFormatterTest.java From fluency with Apache License 2.0 | 6 votes |
private ByteBuffer convertMapToMessagePackByteBuffer(Map<String, Object> record, boolean isDirect) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); byte[] bytes = objectMapper.writeValueAsBytes(record); ByteBuffer byteBuffer; if (isDirect) { byteBuffer = ByteBuffer.allocateDirect(bytes.length); } else { byteBuffer = ByteBuffer.allocate(bytes.length); } byteBuffer.put(bytes); byteBuffer.flip(); return byteBuffer; }
Example #5
Source File: CsvRecordFormatterTest.java From fluency with Apache License 2.0 | 6 votes |
private ByteBuffer convertMapToMessagePackByteBuffer(Map<String, Object> record, boolean isDirect) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); byte[] bytes = objectMapper.writeValueAsBytes(record); ByteBuffer byteBuffer; if (isDirect) { byteBuffer = ByteBuffer.allocateDirect(bytes.length); } else { byteBuffer = ByteBuffer.allocate(bytes.length); } byteBuffer.put(bytes); byteBuffer.flip(); return byteBuffer; }
Example #6
Source File: EncodeMsgPack.java From PacketProxy with Apache License 2.0 | 4 votes |
public EncodeMsgPack(String ALPN) throws Exception { super(ALPN); MessagePackFactory f = new MessagePackFactory(); msgPackMapper = new ObjectMapper(f); jsonMapper = new ObjectMapper(); }
Example #7
Source File: GenericMsgpackRedisSerializer.java From Ffast-Java with MIT License | 4 votes |
public GenericMsgpackRedisSerializer() { this.mapper = new ObjectMapper(new MessagePackFactory()); this.mapper.registerModule((new SimpleModule()).addSerializer(new GenericMsgpackRedisSerializer.NullValueSerializer(null))); this.mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); }
Example #8
Source File: MsgPackJacksonCodec.java From redisson with Apache License 2.0 | 4 votes |
public MsgPackJacksonCodec() { super(new ObjectMapper(new MessagePackFactory())); }
Example #9
Source File: MsgPackJacksonCodec.java From redisson with Apache License 2.0 | 4 votes |
public MsgPackJacksonCodec(ClassLoader classLoader) { super(createObjectMapper(classLoader, new ObjectMapper(new MessagePackFactory()))); }
Example #10
Source File: MessagePackParser.java From secor with Apache License 2.0 | 4 votes |
public MessagePackParser(SecorConfig config) { super(config); mMessagePackObjectMapper = new ObjectMapper(new MessagePackFactory()); mTypeReference = new TypeReference<HashMap<String, Object>>(){}; }
Example #11
Source File: MessagePackParserTest.java From secor with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { mConfig = Mockito.mock(SecorConfig.class); Mockito.when(mConfig.getMessageTimestampName()).thenReturn("ts"); Mockito.when(mConfig.getTimeZone()).thenReturn(TimeZone.getTimeZone("UTC")); Mockito.when(TimestampedMessageParser.usingDateFormat(mConfig)).thenReturn("yyyy-MM-dd"); Mockito.when(TimestampedMessageParser.usingHourFormat(mConfig)).thenReturn("HH"); Mockito.when(TimestampedMessageParser.usingMinuteFormat(mConfig)).thenReturn("mm"); Mockito.when(TimestampedMessageParser.usingDatePrefix(mConfig)).thenReturn("dt="); Mockito.when(TimestampedMessageParser.usingHourPrefix(mConfig)).thenReturn("hr="); Mockito.when(TimestampedMessageParser.usingMinutePrefix(mConfig)).thenReturn("min="); mMessagePackParser = new MessagePackParser(mConfig); mObjectMapper = new ObjectMapper(new MessagePackFactory()); timestamp = System.currentTimeMillis(); HashMap<String, Object> mapWithSecondTimestamp = new HashMap<String, Object>(); mapWithSecondTimestamp.put("ts", 1405970352); mMessageWithSecondsTimestamp = new Message("test", 0, 0, null, mObjectMapper.writeValueAsBytes(mapWithSecondTimestamp), timestamp, null); HashMap<String, Object> mapWithMillisTimestamp = new HashMap<String, Object>(); mapWithMillisTimestamp.put("ts", 1405970352123l); mapWithMillisTimestamp.put("isActive", true); mapWithMillisTimestamp.put("email", "[email protected]"); mapWithMillisTimestamp.put("age", 27); mMessageWithMillisTimestamp = new Message("test", 0, 0, null, mObjectMapper.writeValueAsBytes(mapWithMillisTimestamp), timestamp, null); HashMap<String, Object> mapWithMillisFloatTimestamp = new HashMap<String, Object>(); mapWithMillisFloatTimestamp.put("ts", 1405970352123.0); mapWithMillisFloatTimestamp.put("isActive", false); mapWithMillisFloatTimestamp.put("email", "[email protected]"); mapWithMillisFloatTimestamp.put("age", 35); mMessageWithMillisFloatTimestamp = new Message("test", 0, 0, null, mObjectMapper.writeValueAsBytes(mapWithMillisFloatTimestamp), timestamp, null); HashMap<String, Object> mapWithMillisStringTimestamp = new HashMap<String, Object>(); mapWithMillisStringTimestamp.put("ts", "1405970352123"); mapWithMillisStringTimestamp.put("isActive", null); mapWithMillisStringTimestamp.put("email", "[email protected]"); mapWithMillisStringTimestamp.put("age", 67); mMessageWithMillisStringTimestamp = new Message("test", 0, 0, null, mObjectMapper.writeValueAsBytes(mapWithMillisStringTimestamp), timestamp, null); }