@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); else return new Constants.Value(getSerializer().serialize(((Number) parsed).floatValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a float value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); else return new Constants.Value(getSerializer().serialize(((Number) parsed).floatValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a float value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); else return new Constants.Value(getSerializer().serialize(((Number) parsed).floatValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a float value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); else return new Constants.Value(getSerializer().serialize(((Number) parsed).floatValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a float value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
/** * Returns the typed value, serialized to a ByteBuffer. * * @return a ByteBuffer of the value. * @throws InvalidRequestException if unable to coerce the string to its type. */ public ByteBuffer getByteBuffer() throws InvalidRequestException { switch (type) { case STRING: return AsciiType.instance.fromString(text); case INTEGER: return IntegerType.instance.fromString(text); case UUID: // we specifically want the Lexical class here, not "UUIDType," because we're supposed to have // a uuid-shaped string here, and UUIDType also accepts integer or date strings (and turns them into version 1 uuids). return LexicalUUIDType.instance.fromString(text); case FLOAT: return FloatType.instance.fromString(text); } // FIXME: handle scenario that should never happen return null; }