static ConfidenceValue fromProto()

in sdk-java/src/main/java/com/spotify/confidence/ConfidenceValue.java [162:192]


  static ConfidenceValue fromProto(com.google.protobuf.Value protoValue) {
    final com.google.protobuf.Value.KindCase kind = protoValue.getKindCase();
    switch (kind) {
      case BOOL_VALUE:
        return ConfidenceValue.of(protoValue.getBoolValue());
      case NUMBER_VALUE:
        return ConfidenceValue.of(protoValue.getNumberValue());
      case STRING_VALUE:
        final String stringValue = protoValue.getStringValue();
        try {
          return ConfidenceValue.of(Instant.parse(stringValue));
        } catch (Exception e1) {
          try {
            return ConfidenceValue.of(LocalDate.parse(stringValue));
          } catch (Exception e2) {
            return ConfidenceValue.of(stringValue);
          }
        }
      case NULL_VALUE:
        return NULL_VALUE;
      case STRUCT_VALUE:
        return Struct.fromProto(protoValue.getStructValue());
      case LIST_VALUE:
        final java.util.List<ConfidenceValue> list =
            protoValue.getListValue().getValuesList().stream()
                .map(ConfidenceValue::fromProto)
                .collect(Collectors.toList());
        return new List(list);
    }
    throw new IllegalArgumentException("Unsupported value kind:" + kind);
  }