/** * {@link #deserialize(Map, BiDeserializer)} using default {@link BiDeserializer}. * * @param map to deserialize * @param <T> * * @return deserialized object of the map with deserialized values. */ public <T> T deserialize(Map map) { return deserialize(map, new BiDeserializer(this)); }
/** * Deserialize any object, if possible. * <p> * <ul> <li>if the object is a simple type, e.g. number, string, boolean, it will be simply retured.</li> <li>if the * object is a collection, every item of it will be deserialized the sam way and the result will be returned as a * List with random access (like ArrayList)</li> <li>if the object is a map, it will be processed as with {@link * #deserialize(Map, BiDeserializer)}</li> </ul> * * @param obj to deserealize * @param deserializer to * @param <T> * * @return */ public <T> T deserializeObject(Object obj, BiDeserializer deserializer) { if (obj instanceof String || obj instanceof Number || obj instanceof Boolean || obj instanceof ZonedDateTime || obj instanceof Bytes || obj == null) return (T) obj; if (obj instanceof Map) return deserialize((Map) obj, deserializer); if (obj instanceof Collection) { return (T) ((Collection) obj).stream() .map(x -> deserializeObject(x)) .collect(Collectors.toList()); } throw new IllegalArgumentException("don't know how to deserealize " + obj.getClass().getCanonicalName()); }