graphql.schema.CoercingSerializeException Java Examples

The following examples show how to use graphql.schema.CoercingSerializeException. 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: Scalars.java    From glitr with MIT License 6 votes vote down vote up
@Override
public Object serialize(Object input) {
    if (input == null) {
        return null;
    }

    if (input instanceof Map) {
        return input;
    }

    if (input instanceof String) {
        try {
            return om.readValue((String) input, Map.class);
        } catch (IOException e) {
            throw new CoercingSerializeException("Can't serialize type " + input.getClass() + " with value " + input.toString());
        }
    }

    throw new CoercingSerializeException("Can't serialize type " + input.getClass() + " with value " + input.toString());
}
 
Example #2
Source File: Scalars.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(final Object input) throws CoercingSerializeException {
  if (input instanceof UInt256Value) {
    return ((UInt256Value) input).toShortHexString();
  }
  throw new CoercingSerializeException("Unable to serialize " + input + " as an BigInt");
}
 
Example #3
Source File: JavaScalars.java    From graphql-jpa with MIT License 5 votes vote down vote up
@Override
public Instant parseValue(Object input) {
    if (input instanceof Long) {
        return Instant.ofEpochSecond((Long) input);
    } else if (input instanceof Integer) {
        return Instant.ofEpochSecond((Integer) input);
    }
    throw new CoercingSerializeException(
            "Expected type 'Long' or 'Integer' but was '" + input.getClass().getSimpleName() + "'.");
}
 
Example #4
Source File: JavaScalars.java    From graphql-jpa with MIT License 5 votes vote down vote up
@Override
public Long serialize(Object input) {
    if (input instanceof Instant) {
        return ((Instant) input).getEpochSecond();
    }
    throw new CoercingSerializeException(
            "Expected type 'Instant' but was '" + input.getClass().getSimpleName() + "'.");
}
 
Example #5
Source File: ProtoScalars.java    From rejoiner with Apache License 2.0 5 votes vote down vote up
@Override
public ByteString serialize(Object dataFetcherResult)
    throws CoercingSerializeException {
  if (dataFetcherResult instanceof ByteString) {
    return (ByteString) dataFetcherResult;
  } else {
    throw new CoercingSerializeException(
        "Invalid value '" + dataFetcherResult + "' for Bytes");
  }
}
 
Example #6
Source File: Scalars.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public Number serialize(final Object input) throws CoercingSerializeException {
  if (input instanceof Number) {
    return (Number) input;
  } else if (input instanceof String) {
    final String value = ((String) input).toLowerCase();
    if (value.startsWith("0x")) {
      return Bytes.fromHexStringLenient(value).toLong();
    } else {
      return Long.parseLong(value);
    }
  }
  throw new CoercingSerializeException("Unable to serialize " + input + " as an Long");
}
 
Example #7
Source File: Scalars.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(final Object input) throws CoercingSerializeException {
  if (input instanceof Hash) {
    return ((Hash) input).toString();
  }
  if (input instanceof Bytes32) {
    return input.toString();
  }
  throw new CoercingSerializeException("Unable to serialize " + input + " as an Bytes32");
}
 
Example #8
Source File: Scalars.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(final Object input) throws CoercingSerializeException {
  if (input instanceof Bytes) {
    return input.toString();
  }
  throw new CoercingSerializeException("Unable to serialize " + input + " as an Bytes");
}
 
Example #9
Source File: Scalars.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(final Object input) throws CoercingSerializeException {
  if (input instanceof Address) {
    return input.toString();
  }
  throw new CoercingSerializeException("Unable to serialize " + input + " as an Address");
}
 
Example #10
Source File: AddressScalarTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeErrorTest() {

  thrown.expect(CoercingSerializeException.class);
  scalar.getCoercing().serialize(addrStr);
}
 
Example #11
Source File: LongScalarTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeErrorTest() {
  thrown.expect(CoercingSerializeException.class);
  scalar.getCoercing().serialize(invalidStrValue);
}
 
Example #12
Source File: BytesScalarTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeErrorTest() {
  thrown.expect(CoercingSerializeException.class);
  scalar.getCoercing().serialize(str);
}
 
Example #13
Source File: Bytes32ScalarTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeErrorTest() {
  thrown.expect(CoercingSerializeException.class);
  scalar.getCoercing().serialize(str);
}
 
Example #14
Source File: BigIntScalarTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeErrorTest() {
  thrown.expect(CoercingSerializeException.class);
  scalar.getCoercing().serialize(str);
}
 
Example #15
Source File: _Any.java    From federation-jvm with MIT License 4 votes vote down vote up
@Override
public Object serialize(Object dataFetcherResult) throws CoercingSerializeException {
    return dataFetcherResult;
}
 
Example #16
Source File: SmallRyeGraphQLServerMessages.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Message(id = 12, value = "Expected type [%s] but was [%s].")
CoercingSerializeException coercingSerializeException(String expectedType, String actualType, @Cause Exception cause);
 
Example #17
Source File: Scalars.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
public static CoercingSerializeException serializationException(Object input, Class... allowedTypes) {
    return new CoercingSerializeException(errorMessage(input, allowedTypes));
}