@Test public void testGetFromJsonMap() { String sampleJson = "{" + "\"key1\":\"val1\"," + "\"key2\":[\"val21\", \"val22\"]," + "\"key3\":{\"key31\":false,\"key32\":false}" + "}"; String val1 = Utils.getJsonMapValue(sampleJson, "key1", String.class); assertTrue(val1.equals("val1")); List<String> val2 = Utils.getJsonMapValue(sampleJson, "key2", new TypeToken<List<String>>() { }.getType()); assertTrue(val2.size() == 2); assertTrue(val2.contains("val21")); assertTrue(val2.contains("val22")); Map<String, Boolean> val3 = Utils.getJsonMapValue(sampleJson, "key3", new TypeToken<Map<String, Boolean>>() { }.getType()); assertTrue(val3.size() == 2); assertTrue(val3.containsKey("key31")); assertTrue(val3.containsKey("key32")); }
public static <T> T getJsonMapValue(Object json, String key, Class<T> valueClazz) { JsonElement je = Utils.fromJson(json, JsonElement.class); je = je.getAsJsonObject().get(key); if (je == null) { return null; } return Utils.fromJson(je, valueClazz); }
Utils { public static <T> T getJsonMapValue(Object json, String key, Class<T> valueClazz) { JsonElement je = Utils.fromJson(json, JsonElement.class); je = je.getAsJsonObject().get(key); if (je == null) { return null; } return Utils.fromJson(je, valueClazz); } }
Utils { public static <T> T getJsonMapValue(Object json, String key, Class<T> valueClazz) { JsonElement je = Utils.fromJson(json, JsonElement.class); je = je.getAsJsonObject().get(key); if (je == null) { return null; } return Utils.fromJson(je, valueClazz); } private  Utils(); }
Utils { public static <T> T getJsonMapValue(Object json, String key, Class<T> valueClazz) { JsonElement je = Utils.fromJson(json, JsonElement.class); je = je.getAsJsonObject().get(key); if (je == null) { return null; } return Utils.fromJson(je, valueClazz); } private  Utils(); static void registerCustomJsonMapper(Class<?> clazz,
            JsonMapper mapper); static void registerCustomKryoSerializer(ThreadLocal<Kryo> kryoThreadLocal,
            boolean isDocumentSerializer); static T clone(T t); static T cloneObject(T t); static String computeSignature(ServiceDocument s, ServiceDocumentDescription description); static byte[] getBuffer(int capacity); static int toBytes(Object o, byte[] buffer, int position); static Object fromBytes(byte[] bytes); static Object fromBytes(byte[] bytes, int position, int length); static ServiceDocument fromQueryBinaryDocument(String link, Object binaryData); static void performMaintenance(); static String computeHash(CharSequence content); static String toJson(Object body); static String toJsonHtml(Object body); static String toJson(Set<JsonMapper.JsonOptions> options, Object body); static T fromJson(String json, Class<T> clazz); static T fromJson(Object json, Class<T> clazz); static T fromJson(Object json, Type type); static T getJsonMapValue(Object json, String key, Class<T> valueClazz); static T getJsonMapValue(Object json, String key, Type valueType); static String toString(Throwable t); static String toString(Map<?, Throwable> exceptions); static void log(Class<?> type, String classOrUri, Level level, String fmt,
            Object... args); static void log(Class<?> type, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            String fmt, Object... args); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void logWarning(String fmt, Object... args); static String toDocumentKind(Class<?> type); static String fromDocumentKind(String kind); static String registerKind(Class<?> type, String kind); static Class<?> getTypeFromKind(String kind); static String buildKind(Class<?> type); static ServiceErrorResponse toServiceErrorResponse(Throwable e); static ServiceErrorResponse toValidationErrorResponse(Throwable t, Operation op); static boolean isValidationError(Throwable e); static String buildServicePath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Service service); static String buildCustomUiResourceUriPrefixPath(Service service); static Object setJsonProperty(Object body, String fieldName, String fieldValue); static String validateServiceOption(EnumSet<ServiceOption> options,
            ServiceOption option); static boolean isReachable(SystemHostInfo systemInfo, InetAddress addr, long timeoutMs); static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink,
            String factoryNodeSelectorPath, boolean isAvailable); static boolean isReachableByPing(SystemHostInfo systemInfo, InetAddress addr,
            long timeoutMs); static String getNormalizedHostAddress(SystemHostInfo systemInfo, InetAddress addr); static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
            boolean useBinary); static byte[] encodeBody(Operation op, boolean isRequest); static byte[] encodeBody(Operation op, Object body, String contentType, boolean isRequest); static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest); static void decodeBody(
            Operation op, ByteBuffer buffer, boolean isRequest, boolean compressed); static String decodeIfText(ByteBuffer buffer, String contentType); static ByteBuffer compressGZip(String text); static boolean isContentTypeKryoBinary(String contentType); static Path getServiceUiResourcePath(Service s); static boolean mergeWithState(
            ServiceDocumentDescription desc,
            T source, T patch); static boolean mergeWithState(T currentState, Operation op); static EnumSet<MergeResult> mergeWithStateAdvanced(
            ServiceDocumentDescription desc, T currentState, Class<T> type, Operation op); static void validateState(
            ServiceDocumentDescription desc, T state); static long fromNowMicrosUtc(long deltaMicros); static boolean beforeNow(long microsUtc); static long getSystemNowMicrosUtc(); static long getNowMicrosUtc(); static void setTimeDriftThreshold(long micros); static void resetTimeComparisonEpsilonMicros(); static void setTimeComparisonEpsilonMicros(long micros); static long getTimeComparisonEpsilonMicros(); static boolean isWithinTimeComparisonEpsilon(long timeMicros); static StringBuilder getBuilder(); static boolean updateCollections(T currentState,
            ServiceStateCollectionUpdateRequest patchBody); static boolean updateMaps(T currentState,
            ServiceStateMapUpdateRequest patchBody); static String buildUUID(String id); static T buildServiceConfig(T config, Service service); }
Utils { public static <T> T getJsonMapValue(Object json, String key, Class<T> valueClazz) { JsonElement je = Utils.fromJson(json, JsonElement.class); je = je.getAsJsonObject().get(key); if (je == null) { return null; } return Utils.fromJson(je, valueClazz); } private  Utils(); static void registerCustomJsonMapper(Class<?> clazz,
            JsonMapper mapper); static void registerCustomKryoSerializer(ThreadLocal<Kryo> kryoThreadLocal,
            boolean isDocumentSerializer); static T clone(T t); static T cloneObject(T t); static String computeSignature(ServiceDocument s, ServiceDocumentDescription description); static byte[] getBuffer(int capacity); static int toBytes(Object o, byte[] buffer, int position); static Object fromBytes(byte[] bytes); static Object fromBytes(byte[] bytes, int position, int length); static ServiceDocument fromQueryBinaryDocument(String link, Object binaryData); static void performMaintenance(); static String computeHash(CharSequence content); static String toJson(Object body); static String toJsonHtml(Object body); static String toJson(Set<JsonMapper.JsonOptions> options, Object body); static T fromJson(String json, Class<T> clazz); static T fromJson(Object json, Class<T> clazz); static T fromJson(Object json, Type type); static T getJsonMapValue(Object json, String key, Class<T> valueClazz); static T getJsonMapValue(Object json, String key, Type valueType); static String toString(Throwable t); static String toString(Map<?, Throwable> exceptions); static void log(Class<?> type, String classOrUri, Level level, String fmt,
            Object... args); static void log(Class<?> type, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            String fmt, Object... args); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void logWarning(String fmt, Object... args); static String toDocumentKind(Class<?> type); static String fromDocumentKind(String kind); static String registerKind(Class<?> type, String kind); static Class<?> getTypeFromKind(String kind); static String buildKind(Class<?> type); static ServiceErrorResponse toServiceErrorResponse(Throwable e); static ServiceErrorResponse toValidationErrorResponse(Throwable t, Operation op); static boolean isValidationError(Throwable e); static String buildServicePath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Service service); static String buildCustomUiResourceUriPrefixPath(Service service); static Object setJsonProperty(Object body, String fieldName, String fieldValue); static String validateServiceOption(EnumSet<ServiceOption> options,
            ServiceOption option); static boolean isReachable(SystemHostInfo systemInfo, InetAddress addr, long timeoutMs); static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink,
            String factoryNodeSelectorPath, boolean isAvailable); static boolean isReachableByPing(SystemHostInfo systemInfo, InetAddress addr,
            long timeoutMs); static String getNormalizedHostAddress(SystemHostInfo systemInfo, InetAddress addr); static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
            boolean useBinary); static byte[] encodeBody(Operation op, boolean isRequest); static byte[] encodeBody(Operation op, Object body, String contentType, boolean isRequest); static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest); static void decodeBody(
            Operation op, ByteBuffer buffer, boolean isRequest, boolean compressed); static String decodeIfText(ByteBuffer buffer, String contentType); static ByteBuffer compressGZip(String text); static boolean isContentTypeKryoBinary(String contentType); static Path getServiceUiResourcePath(Service s); static boolean mergeWithState(
            ServiceDocumentDescription desc,
            T source, T patch); static boolean mergeWithState(T currentState, Operation op); static EnumSet<MergeResult> mergeWithStateAdvanced(
            ServiceDocumentDescription desc, T currentState, Class<T> type, Operation op); static void validateState(
            ServiceDocumentDescription desc, T state); static long fromNowMicrosUtc(long deltaMicros); static boolean beforeNow(long microsUtc); static long getSystemNowMicrosUtc(); static long getNowMicrosUtc(); static void setTimeDriftThreshold(long micros); static void resetTimeComparisonEpsilonMicros(); static void setTimeComparisonEpsilonMicros(long micros); static long getTimeComparisonEpsilonMicros(); static boolean isWithinTimeComparisonEpsilon(long timeMicros); static StringBuilder getBuilder(); static boolean updateCollections(T currentState,
            ServiceStateCollectionUpdateRequest patchBody); static boolean updateMaps(T currentState,
            ServiceStateMapUpdateRequest patchBody); static String buildUUID(String id); static T buildServiceConfig(T config, Service service); static final String PROPERTY_NAME_PREFIX; static final Charset CHARSET_OBJECT; static final String CHARSET; static final String UI_DIRECTORY_NAME; static final String PROPERTY_NAME_TIME_COMPARISON; static final int DEFAULT_IO_THREAD_COUNT; static final int DEFAULT_THREAD_COUNT; static final long DEFAULT_TIME_DRIFT_THRESHOLD_MICROS; }