Search in sources :

Example 1 with JsonMediaTypeCodec

use of io.micronaut.json.codec.JsonMediaTypeCodec in project micronaut-core by micronaut-projects.

the class JsonViewMediaTypeCodecFactory method resolveJsonViewCodec.

/**
 * Creates a {@link JsonMediaTypeCodec} for the view class (specified as the JsonView annotation value).
 * @param viewClass The view class
 * @return The codec
 */
@Override
@NonNull
public JsonMediaTypeCodec resolveJsonViewCodec(@NonNull Class<?> viewClass) {
    ArgumentUtils.requireNonNull("viewClass", viewClass);
    JsonMediaTypeCodec codec = jsonViewCodecs.get(viewClass);
    if (codec == null) {
        codec = (JsonMediaTypeCodec) jsonCodec.cloneWithViewClass(viewClass);
        jsonViewCodecs.put(viewClass, codec);
    }
    return codec;
}
Also used : JsonMediaTypeCodec(io.micronaut.json.codec.JsonMediaTypeCodec) NonNull(io.micronaut.core.annotation.NonNull)

Example 2 with JsonMediaTypeCodec

use of io.micronaut.json.codec.JsonMediaTypeCodec in project micronaut-core by micronaut-projects.

the class DefaultHttpClient method createDefaultMediaTypeRegistry.

private static MediaTypeCodecRegistry createDefaultMediaTypeRegistry() {
    JsonMapper mapper = new JacksonDatabindMapper();
    ApplicationConfiguration configuration = new ApplicationConfiguration();
    return MediaTypeCodecRegistry.of(new JsonMediaTypeCodec(mapper, configuration, null), new JsonStreamMediaTypeCodec(mapper, configuration, null));
}
Also used : JsonMapper(io.micronaut.json.JsonMapper) JsonStreamMediaTypeCodec(io.micronaut.json.codec.JsonStreamMediaTypeCodec) JsonMediaTypeCodec(io.micronaut.json.codec.JsonMediaTypeCodec) JacksonDatabindMapper(io.micronaut.jackson.databind.JacksonDatabindMapper) ApplicationConfiguration(io.micronaut.runtime.ApplicationConfiguration)

Aggregations

JsonMediaTypeCodec (io.micronaut.json.codec.JsonMediaTypeCodec)2 NonNull (io.micronaut.core.annotation.NonNull)1 JacksonDatabindMapper (io.micronaut.jackson.databind.JacksonDatabindMapper)1 JsonMapper (io.micronaut.json.JsonMapper)1 JsonStreamMediaTypeCodec (io.micronaut.json.codec.JsonStreamMediaTypeCodec)1 ApplicationConfiguration (io.micronaut.runtime.ApplicationConfiguration)1