fromInputStream using generics

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-08-13 17:53:15 -03:00
parent f11c773f8a
commit 47ca69c435
1 changed files with 11 additions and 1 deletions

View File

@ -61,7 +61,17 @@ public final class Json {
throw new IllegalStateException("Failed to encode as JSON: " + e.getMessage());
}
}
public static <T> T fromInputStream(final InputStream inputStream,
Class<T> clazz) {
try {
return MAPPER.readValue(inputStream, clazz);
} catch (Exception e) {
throw new IllegalStateException("Failed to encode as JSON: "
+ e.getMessage());
}
}
/**
* Decode a given JSON string to a CloudEvent .
*