Implementation of DataUnmarshaller for JSON
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
d040bcef32
commit
0606036c31
|
|
@ -20,6 +20,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
|
||||
import io.cloudevents.Attributes;
|
||||
import io.cloudevents.fun.DataUnmarshaller;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
|
|
@ -96,6 +99,23 @@ public final class Json {
|
|||
throw new IllegalStateException("Failed to decode: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSON Data Unmarshaller
|
||||
* @param <T> The 'data' type
|
||||
* @param <A> The attributes type
|
||||
* @param type The type of 'data'
|
||||
* @return A new instance of {@link DataUnmarshaller}
|
||||
*/
|
||||
public static <T, A extends Attributes>
|
||||
DataUnmarshaller<String, T, A> umarshaller(Class<T> type) {
|
||||
return new DataUnmarshaller<String, T, A>() {
|
||||
@Override
|
||||
public T unmarshall(String payload, A attributes) throws Exception {
|
||||
return Json.decodeValue(payload, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Json() {
|
||||
// no-op
|
||||
|
|
|
|||
Loading…
Reference in New Issue