Search in sources :

Example 1 with AbstractEurekaJacksonCodec

use of com.netflix.discovery.converters.jackson.AbstractEurekaJacksonCodec in project eureka by Netflix.

the class CodecLoadTester method createJacksonNgAction.

Func0 createJacksonNgAction(final MediaType mediaType, final boolean compact) {
    return new Func0<Object>() {

        @Override
        public int call(Object object) {
            AbstractEurekaJacksonCodec codec;
            if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                codec = compact ? jsonCodecNgCompact : jsonCodecNG;
            } else {
                codec = compact ? xmlCodecNgCompact : xmlCodecNG;
            }
            ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
            try {
                codec.writeTo(object, captureStream);
                byte[] bytes = captureStream.toByteArray();
                InputStream source = new ByteArrayInputStream(bytes);
                Applications readValue = codec.getObjectMapper(object.getClass()).readValue(source, Applications.class);
                secondHolder.value = readValue;
                return bytes.length;
            } catch (IOException e) {
                throw new RuntimeException("unexpected", e);
            }
        }
    };
}
Also used : AbstractEurekaJacksonCodec(com.netflix.discovery.converters.jackson.AbstractEurekaJacksonCodec) Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

AbstractEurekaJacksonCodec (com.netflix.discovery.converters.jackson.AbstractEurekaJacksonCodec)1 Applications (com.netflix.discovery.shared.Applications)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1