public static ValueWithTypeDto getFundamentalValueFromJson()

in api/applib/src/main/java/org/apache/causeway/applib/util/schema/CommonDtoUtils.java [73:190]


    public static ValueWithTypeDto getFundamentalValueFromJson(
            final @NonNull ValueType valueType,
            final @Nullable String json) {
        val valueDto = new ValueWithTypeDto();
        valueDto.setType(valueType);

        if(_Strings.isNullOrEmpty(json)) {
            return valueDto;
        }

        switch(valueType) {
        case REFERENCE:
        case COMPOSITE:
        case COLLECTION:
            throw _Exceptions.unsupportedOperation("valueType %s is not fundamental", valueType);

        case STRING: {
            valueDto.setString(json);
            return valueDto;
        }
        case BYTE: {
            valueDto.setByte(Byte.valueOf(json));
            return valueDto;
        }
        case SHORT: {
            valueDto.setShort(Short.valueOf(json));
            return valueDto;
        }
        case INT: {
            valueDto.setInt(Integer.valueOf(json));
            return valueDto;
        }
        case LONG: {
            valueDto.setLong(Long.valueOf(json));
            return valueDto;
        }
        case CHAR: {
            valueDto.setChar(json);
            return valueDto;
        }
        case BOOLEAN: {
            valueDto.setBoolean(Boolean.valueOf(json));
            return valueDto;
        }
        case FLOAT: {
            valueDto.setFloat(Float.valueOf(json));
            return valueDto;
        }
        case DOUBLE: {
            valueDto.setDouble(Double.valueOf(json));
            return valueDto;
        }
        case BIG_INTEGER: {
            valueDto.setBigInteger(new BigInteger(json));
            return valueDto;
        }
        case BIG_DECIMAL: {
            valueDto.setBigDecimal(new BigDecimal(json));
            return valueDto;
        }
        case LOCAL_DATE: {
            final LocalDate argValue = LocalDate.parse(json);
            valueDto.setLocalDate(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case LOCAL_TIME: {
            final LocalTime argValue = LocalTime.parse(json);
            valueDto.setLocalTime(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case LOCAL_DATE_TIME: {
            final LocalDateTime argValue = LocalDateTime.parse(json);
            valueDto.setLocalDateTime(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case OFFSET_DATE_TIME: {
            final OffsetDateTime argValue = OffsetDateTime.parse(json);
            valueDto.setOffsetDateTime(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case OFFSET_TIME: {
            final OffsetTime argValue = OffsetTime.parse(json);
            valueDto.setOffsetTime(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case ZONED_DATE_TIME: {
            final ZonedDateTime argValue = ZonedDateTime.parse(json);
            valueDto.setZonedDateTime(JavaTimeXMLGregorianCalendarMarshalling.toXMLGregorianCalendar(argValue));
            return valueDto;
        }
        case ENUM: {
            final EnumDto enumDto = JsonUtils.tryRead(EnumDto.class, json)
                    .ifFailureFail()
                    .getValue().orElseThrow();
            valueDto.setEnum(enumDto);
            return valueDto;
        }
        case BLOB: {
            final BlobDto blobDto = JsonUtils.tryRead(BlobDto.class, json)
                    .ifFailureFail()
                    .getValue().orElseThrow();
            valueDto.setBlob(blobDto);
            return valueDto;
        }
        case CLOB: {
            final ClobDto clobDto = JsonUtils.tryRead(ClobDto.class, json)
                    .ifFailureFail()
                    .getValue().orElseThrow();
            valueDto.setClob(clobDto);
            return valueDto;
        }
        case VOID:
            return valueDto;
        }

        throw _Exceptions.unmatchedCase(valueType);

    }