Java Code Examples for javax.json.JsonValue#NULL

The following examples show how to use javax.json.JsonValue#NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONEntityState.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private boolean stateCloneWithAssociation( String stateName, EntityReference ref )
{
    JsonObject valueState = state.getJsonObject( JSONKeys.VALUE );
    JsonValue jsonRef = ref == null ? JsonValue.NULL : jsonFactories.toJsonString( ref.identity().toString() );
    if( Objects.equals( valueState.get( stateName ), jsonRef ) )
    {
        return false;
    }
    valueState = jsonFactories.cloneBuilderExclude( valueState, stateName )
                              .add( stateName, jsonRef )
                              .build();
    state = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE )
                         .add( JSONKeys.VALUE, valueState )
                         .build();
    return true;
}
 
Example 2
Source File: JsonHelper.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * JsonArrayまたはJsonObjectをCollectionに変換します<br>
 * JsonObjectの場合は単一のオブジェクトだけを格納しているCollectionを返します
 *
 * @param <T> JsonArrayの内容の型
 * @param <R> functionの戻り値の型
 * @param <C> 変換後のCollectionの型
 * @param value 変換するJsonArrayまたはJsonObject
 * @param function JsonValueを受け取って変換するFunction
 * @param supplier Collectionインスタンスを供給するSupplier
 * @return 変換後のCollection
 */
@SuppressWarnings("unchecked")
public static <T extends JsonValue, C extends Collection<R>, R> C toCollection(JsonValue value,
        Function<T, R> function, Supplier<C> supplier) {
    C collection = supplier.get();
    if (value instanceof JsonArray) {
        for (JsonValue val : (JsonArray) value) {
            if (val == null || val == JsonValue.NULL) {
                collection.add(null);
            } else {
                collection.add(function.apply((T) val));
            }
        }
    } else {
        collection.add(function.apply((T) value));
    }
    return collection;
}
 
Example 3
Source File: InputsHandler.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
public InputFactory asInputFactory() {
    return name -> {
        final BaseIOHandler.IO ref = connections.get(getActualName(name));
        if (ref == null || !ref.hasNext()) {
            return null;
        }

        final Object value = ref.next();
        if (value instanceof Record) {
            return value;
        }
        final Object convertedValue;
        final RecordConverters.MappingMeta mappingMeta = registry.find(value.getClass(), () -> recordBuilderMapper);
        if (mappingMeta.isLinearMapping()) {
            convertedValue = value;
        } else {
            if (value instanceof javax.json.JsonValue) {
                if (JsonValue.NULL == value) { // JsonObject cant take a JsonValue so pass null
                    return null;
                }
                convertedValue = value.toString();
            } else {
                convertedValue = jsonb.toJson(value);
            }
        }

        return converters.toRecord(registry, convertedValue, () -> jsonb, () -> recordBuilderMapper);
    };
}
 
Example 4
Source File: JsonpRuntime.java    From jmespath-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JsonValue getProperty(JsonValue value, JsonValue name) {
  if (value.getValueType() == OBJECT) {
    return nodeOrNullNode(((JsonObject) value).get(toString(name)));
  } else {
    return JsonValue.NULL;
  }
}
 
Example 5
Source File: JsonpRuntime.java    From jmespath-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JsonValue nodeOrNullNode(JsonValue node) {
  if (node == null) {
    return JsonValue.NULL;
  } else {
    return node;
  }
}
 
Example 6
Source File: JavaxJsonSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings( "unchecked" )
private JsonValue doSerialize( Options options, Object object, boolean root )
{
    if( object == null )
    {
        return JsonValue.NULL;
    }
    Class<?> objectClass = object.getClass();
    Converter<Object> converter = converters.converterFor( objectClass );
    if( converter != null )
    {
        return doSerialize( options, converter.toString( object ), false );
    }
    JavaxJsonAdapter<?> adapter = adapters.adapterFor( objectClass );
    if( adapter != null )
    {
        return adapter.serialize( jsonFactories, object, obj -> doSerialize( options, obj, false ) );
    }
    if( StatefulAssociationValueType.isStatefulAssociationValue( objectClass ) )
    {
        return serializeStatefulAssociationValue( options, object, root );
    }
    if( MapType.isMap( objectClass ) )
    {
        return serializeMap( options, (Map<?, ?>) object );
    }
    if( ArrayType.isArray( objectClass ) )
    {
        return serializeArray( options, object );
    }
    if( Iterable.class.isAssignableFrom( objectClass ) )
    {
        return serializeIterable( options, (Iterable<?>) object );
    }
    if( Stream.class.isAssignableFrom( objectClass ) )
    {
        return serializeStream( options, (Stream<?>) object );
    }
    throw new SerializationException( "Don't know how to serialize " + object );
}
 
Example 7
Source File: JSONEntityState.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public EntityReference associationValueOf( QualifiedName stateName )
{
    JsonValue associationValue = state.getJsonObject( JSONKeys.VALUE ).get( stateName.name() );
    if( associationValue == JsonValue.NULL )
    {
        return null;
    }
    return EntityReference.parseEntityReference( ( (JsonString) associationValue ).getString() );
}
 
Example 8
Source File: JsonHelper.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * keyで取得したJsonValueをconverterで変換したものをconsumerへ設定します<br>
 *
 * @param <T> JsonObject#get(Object) の戻り値の型
 * @param <R> converterの戻り値の型
 * @param key JsonObjectから取得するキー
 * @param consumer converterの戻り値を消費するConsumer
 * @param converter JsonValueを変換するFunction
 * @return {@link Bind}
 */
@SuppressWarnings("unchecked")
public <T extends JsonValue, R> Bind set(String key, Consumer<R> consumer, Function<T, R> converter) {
    JsonValue val = this.json.get(key);
    if (val != null && JsonValue.NULL != val) {
        R obj = converter.apply((T) val);
        consumer.accept(obj);
        if (this.listener != null) {
            this.listener.apply(key, val, obj);
        }
    }
    return this;
}
 
Example 9
Source File: DataValueJsonValue.java    From tcases with MIT License 4 votes vote down vote up
public void visit( NullValue data)
{
json_ = JsonValue.NULL;
}
 
Example 10
Source File: RequestCaseJson.java    From tcases with MIT License 4 votes vote down vote up
public void visit( NullValue data)
{
json_ = JsonValue.NULL;
}
 
Example 11
Source File: Json2Xml.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isNil(XSElementDeclaration elementDeclaration, JsonValue node) {
	boolean result=node==JsonValue.NULL;
	if (log.isTraceEnabled()) log.trace("isNil() node ["+node+"] = ["+result+"]");
	return result;
}
 
Example 12
Source File: JsonHelper.java    From logbook-kai with MIT License 3 votes vote down vote up
/**
 * JsonValueを任意のオブジェクトに変換します
 *
 * @param <T> JsonValueの実際の型
 * @param <R> functionの戻り値の型
 * @param val 型Rに変換するJsonValue
 * @param function 変換Function
 * @return 変換後のオブジェクト
 */
public static <T extends JsonValue, R> R toObject(T val, Function<T, R> function) {
    if (val == null || val == JsonValue.NULL) {
        return null;
    }
    return function.apply(val);
}