use of com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream in project jackson-databind by FasterXML.
the class ByteBufferSerializer method serialize.
@Override
public void serialize(ByteBuffer bbuf, JsonGenerator gen, SerializerProvider provider) throws IOException {
// first, simple case when wrapping an array...
if (bbuf.hasArray()) {
gen.writeBinary(bbuf.array(), 0, bbuf.limit());
return;
}
// the other case is more complicated however. Best to handle with InputStream wrapper.
// But should we rewind it; and/or make a copy?
ByteBuffer copy = bbuf.asReadOnlyBuffer();
if (copy.position() > 0) {
copy.rewind();
}
InputStream in = new ByteBufferBackedInputStream(copy);
gen.writeBinary(in, copy.remaining());
in.close();
}
use of com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream in project chassis by Kixeye.
the class RawWebSocketMessage method deserialize.
/**
* Deserializes the given message.
*
* @param action
* @return
* @throws Exception
*/
public T deserialize(WebSocketAction action) throws Exception {
// first deserialize
T message = null;
if (messageClass != null) {
message = serDe.deserialize(new ByteBufferBackedInputStream(rawData), messageClass);
}
// then validate
if (message != null && action.shouldValidatePayload()) {
SpringValidatorAdapter validatorAdapter = new SpringValidatorAdapter(messageValidator);
BeanPropertyBindingResult result = new BeanPropertyBindingResult(message, messageClass.getName());
validatorAdapter.validate(message, result);
if (result.hasErrors()) {
throw new MethodArgumentNotValidException(new MethodParameter(action.getMethod(), action.getPayloadParameterIndex()), result);
}
}
return message;
}
Aggregations