StringTypeConverter implements TypeConverter { public String fromNative(Object nativeValue, FromNativeContext context) { Number nativeValueAsNumber = (Number) nativeValue; if (nativeValueAsNumber == null) { return null; } ID id = ID.fromLong(nativeValueAsNumber.longValue()); if (id.isNull()) { return null; } return Foundation.toString(id); }  Class<?> nativeType(); String fromNative(Object nativeValue, FromNativeContext context); Object toNative(Object value, ToNativeContext context);  }
@Test public void convertsReturnedIDToString() { ID helloID = Foundation.cfString("Hello"); Number nativeValue = new Long(helloID.longValue()); String converted = converter.fromNative(nativeValue, null); assertEquals("Hello", converted); if (NativeLong.SIZE == 4) { nativeValue = new Integer(helloID.intValue()); converted = converter.fromNative(nativeValue, null); assertEquals("Hello", converted); } }
@Test public void convertsReturnedNilToNull() { Number nativeValue = new Long(0); assertNull(converter.fromNative(nativeValue, null)); }