static String formatMessage( long duration, Object object ) { return String.format( TIMER_THRESHOLD_TRIGGERED_MSG, duration, JsonUtils.mapToFormattedJsonString( object ) ); } }
@Override public String toString() { if ( batch != null ) { return JsonUtils.mapToJsonString( batch ); } else if ( list != null ) { return JsonUtils.mapToJsonString( list ); } return JsonUtils.mapToJsonString( properties ); }
public static Object deserializePropertyValueFromJsonBinary( ByteBuffer bytes, Class<?> classType ) { return JsonUtils.normalizeJsonTree( JsonUtils.fromByteBuffer( bytes, classType ) ); }
uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); normalizeJsonTree( o ); UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid;
@SuppressWarnings("unchecked") @Test public void testJson() throws Exception { User user = new User(); // user.setId(UUIDUtils.newTimeUUID()); user.setProperty( "foo", "bar" ); assertEquals( "{\"type\":\"user\",\"foo\":\"bar\"}", JsonUtils.mapToJsonString( user ) ); String json = "{\"username\":\"edanuff\", \"bar\" : \"baz\" }"; Map<String, Object> p = ( Map<String, Object> ) JsonUtils.parse( json ); user = new User(); user.addProperties( p ); assertEquals( "edanuff", user.getUsername() ); assertEquals( "baz", user.getProperty( "bar" ) ); json = "{\"username\":\"edanuff\", \"foo\" : {\"a\":\"bar\", \"b\" : \"baz\" } }"; p = ( Map<String, Object> ) JsonUtils.parse( json ); user = new User(); user.addProperties( p ); assertEquals( "edanuff", user.getUsername() ); assertTrue( Map.class.isAssignableFrom( user.getProperty( "foo" ).getClass() ) ); assertEquals( "baz", ( ( Map<String, Object> ) user.getProperty( "foo" ) ).get( "b" ) ); } }
@SuppressWarnings("unchecked") @Test public void testUnroll() { Map<String, Object> json = new LinkedHashMap<String, Object>(); json.put( "name", "edanuff" ); json.put( "cat", "fishbone" ); json.put( "city", "San Francisco" ); json.put( "car", "bmw" ); json.put( "stuff", Arrays.asList( 1, 2, 3, 4, 5 ) ); json.put( "phones", Arrays.asList( MapUtils.map( "a", "b" ), MapUtils.map( "a", "c" ), MapUtils.map( "b", MapUtils.map( "d", "e", "d", "f" ) ) ) ); dumpJson( "obj", json ); dumpJson( "propname", Arrays.asList( 1, 2, 3, 4, 5 ) ); dumpJson( "propname", 125 ); System.out.println( JsonUtils.mapToJsonString( json ) ); Object result = JsonUtils.select( json, "phones" ); System.out.println( JsonUtils.mapToJsonString( result ) ); result = JsonUtils.select( json, "phones.a" ); System.out.println( JsonUtils.mapToJsonString( result ) ); }
public static ServicePayload stringPayload( String str ) { return jsonPayload( JsonUtils.parse( str ) ); }
@SuppressWarnings("unchecked") public static ServicePayload jsonPayload( Object json ) { ServicePayload payload = null; json = normalizeJsonTree( json ); if ( json instanceof Map ) { Map<String, Object> jsonMap = ( Map<String, Object> ) json; payload = payload( jsonMap ); } else if ( json instanceof List ) { List<?> jsonList = ( List<?> ) json; if ( jsonList.size() > 0 ) { if ( jsonList.get( 0 ) instanceof UUID ) { payload = idListPayload( ( List<UUID> ) json ); } else if ( jsonList.get( 0 ) instanceof Map ) { payload = ServicePayload.batchPayload( ( List<Map<String, Object>> ) jsonList ); } } } return payload; }
public static Object select( Object obj, String path ) { return select( obj, path, false ); }
String newPath; String key = e.getKey().toString(); key = quoteString( key ); if ( key.indexOf( '\\' ) == -1 ) { if ( path != null ) { String newPath; String key = e.getKey(); key = quoteString( key ); if ( key.indexOf( '\\' ) == -1 ) { if ( path != null ) { buildKeyValueSet( toJsonNode( node ), keyValues, path, fulltextIndex, history );
public static Object fromByteBuffer( ByteBuffer byteBuffer ) { return fromByteBuffer( byteBuffer, Object.class ); }
root.put( "array", new String[] { "val1", "val2", "val3 with spaces" } ); Map<String, Object> jsonData = ( Map<String, Object> ) JsonUtils.parse( JsonUtils.mapToJsonString( root ) );
@Override public Optional<Map<String, Object>> getCollectionSettings(final String collectionName ) { String settings; settings = cache.get(scope); if( settings == null ) { settings = mapManager.getString(collectionName); } if (settings != null) { if( settings.isEmpty() ){ return Optional.absent(); // empty string means it's empty. we store empty string for cache purposes }else{ return Optional.of((Map<String, Object>) JsonUtils.parse(settings)); } }else{ cache.put(scope, ""); // store empty string here so empty is cached as well } return Optional.absent(); }
@Test public void testNormalize() { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put( "foo", "bar" ); Object o = JsonUtils.normalizeJsonTree( node ); assertEquals( java.util.LinkedHashMap.class, o.getClass() ); } }
Map<?, ?> map = ( Map<?, ?> ) obj; Object child = map.get( segment ); Object result = select( child, remaining, buildResultTree ); if ( result != null ) { if ( buildResultTree ) { List<?> list = ( List<?> ) obj; for ( Object i : list ) { Object result = select( i, path, buildResultTree ); if ( result != null ) { results.add( result ); Object result = select( child, remaining, buildResultTree ); if ( result != null ) { if ( buildResultTree ) {
public static Queue deserializeQueue( List<HColumn<String, ByteBuffer>> columns ) { Queue queue = null; Map<String, Object> properties = new HashMap<String, Object>(); for ( HColumn<String, ByteBuffer> column : columns ) { if ( QUEUE_PROPERTIES.containsKey( column.getName() ) ) { properties .put( column.getName(), object( QUEUE_PROPERTIES.get( column.getName() ), column.getValue() ) ); } else { properties.put( column.getName(), JsonUtils.fromByteBuffer( column.getValue() ) ); } } if ( !properties.isEmpty() ) { queue = new Queue( properties ); } return queue; }
public void dump( String name, Object obj ) { if ( obj != null && logger.isInfoEnabled() ) { logger.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) ); } } }
collectionSettings.putCollectionSettings( collectionName, JsonUtils.mapToJsonString( updatedSettings ) );
public static CounterQuery fromJsonString( String json ) { Object o = JsonUtils.parse( json ); if ( o instanceof Map ) { @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, List<String>> params = cast( toMapList( ( Map ) o ) ); return fromQueryParams( params ); } return null; }
public static Object deserializePropertyValueFromJsonBinary( ByteBuffer bytes ) { return JsonUtils.normalizeJsonTree( JsonUtils.fromByteBuffer( bytes ) ); }