Package dev.relism.flash.ext.jackson
Class Codec
java.lang.Object
dev.relism.flash.ext.jackson.Codec
One Jackson mapper, in the shape a handler needs it.
Every Jackson data format is the same databind model behind a different factory, so this is the whole of what a format module has to say: which mapper, and which content type it writes. What the annotations mean, what a body is checked against and how a type is described are the same for all of them.
Retrieve it once at boot — @Inject private Json json; — and call it on the hot path.
The underlying ObjectMapper is thread-safe once configured.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCodec(com.fasterxml.jackson.databind.ObjectMapper mapper, dev.relism.flash.http.ContentType contentType) -
Method Summary
Modifier and TypeMethodDescription<T> TReads the request body astypeand verifies its constraints.dev.relism.flash.http.ContentTypeWhat this codec writes, for a handler that sets the response type itself.com.fasterxml.jackson.databind.ObjectMappermapper()The mapper itself, for everything these methods do not cover.Serializesvalueand sets this codec's content type on the response.Likewrite(dev.relism.flash.models.Response, java.lang.Object), restricted to the fields visible under a Jackson@JsonView.
-
Constructor Details
-
Codec
protected Codec(com.fasterxml.jackson.databind.ObjectMapper mapper, dev.relism.flash.http.ContentType contentType)
-
-
Method Details
-
body
Reads the request body astypeand verifies its constraints.Read straight off the request's stream, which Flash reuses per connection: nothing buffers the body to hand it over. A type that declares no constraints is not checked at all.
- Throws:
dev.relism.flash.exceptions.HttpException- 400 if the body cannot be parsed astypeValidationException- 422 if it parses but violates a constraintException
-
write
Serializesvalueand sets this codec's content type on the response.- Throws:
Exception
-
writeView
public String writeView(dev.relism.flash.models.Response response, Object value, Class<?> view) throws Exception Likewrite(dev.relism.flash.models.Response, java.lang.Object), restricted to the fields visible under a Jackson@JsonView.- Throws:
Exception
-
contentType
public dev.relism.flash.http.ContentType contentType()What this codec writes, for a handler that sets the response type itself. -
mapper
public com.fasterxml.jackson.databind.ObjectMapper mapper()The mapper itself, for everything these methods do not cover.
-