Permalink
Browse files

QI-318 Explicit Character/char support

  • Loading branch information...
eskatos committed Feb 17, 2013
1 parent d6dc0c9 commit 85c1ca26a6b2ab58bf5fa31e046127003708236b
@@ -51,6 +51,7 @@ EntityComposites and EntityReferences are serialized as their identity string.
Plain Values can be one of :
* String,
+ * Character or char,
* Boolean or boolean,
* Integer or int,
* Long or long,
@@ -42,6 +42,7 @@
* </p>
* <ul>
* <li>String,</li>
+ * <li>Character or char,</li>
* <li>Boolean or boolean,</li>
* <li>Integer or int,</li>
* <li>Long or long,</li>
@@ -41,6 +41,7 @@
* </p>
* <ul>
* <li>String,</li>
+ * <li>Character or char,</li>
* <li>Boolean or boolean,</li>
* <li>Integer or int,</li>
* <li>Long or long,</li>
@@ -71,6 +71,7 @@
* </p>
* <ul>
* <li>String,</li>
+ * <li>Character or char,</li>
* <li>Boolean or boolean,</li>
* <li>Integer or int,</li>
* <li>Long or long,</li>
@@ -136,6 +137,14 @@ public String map( Object input )
return input.toString();
}
} );
+ registerDeserializer( Character.class, new Function<Object, Character>()
+ {
+ @Override
+ public Character map( Object input )
+ {
+ return input.toString().charAt( 0 );
+ }
+ } );
registerDeserializer( Boolean.class, new Function<Object, Boolean>()
{
@Override
@@ -61,6 +61,7 @@
* </p>
* <ul>
* <li>String,</li>
+ * <li>Character or char,</li>
* <li>Boolean or boolean,</li>
* <li>Integer or int,</li>
* <li>Long or long,</li>
@@ -97,6 +98,7 @@ public ValueSerializerAdapter()
{
// Primitive Value types
registerSerializer( String.class, Functions.<Object, String>identity() );
+ registerSerializer( Character.class, Functions.<Object, Character>identity() );
registerSerializer( Boolean.class, Functions.<Object, Boolean>identity() );
registerSerializer( Integer.class, Functions.<Object, Integer>identity() );
registerSerializer( Long.class, Functions.<Object, Long>identity() );
@@ -132,6 +132,16 @@ public void givenCollectionTypeWithByteAndNullElementWhenSerializingAndDeseriali
assertEquals( new LinkedHashSet<Byte>( byteCollection() ), list );
}
+ @Test
+ public void givenCollectionTypeWithCharacterAndNullElementWhenSerializingAndDeserializingExpectEquals()
+ throws Exception
+ {
+ String output = valueSerialization.serialize( characterCollection() );
+ CollectionType collectionType = new CollectionType( List.class, new ValueType( Character.class ) );
+ List<Character> list = valueSerialization.deserialize( collectionType, output );
+ assertEquals( characterCollection(), list );
+ }
+
@Test
public void givenCollectionTypeWithShortAndNullElementWhenSerializingAndDeserializingExpectEquals()
throws Exception
@@ -259,6 +269,17 @@ public void givenListOfValueCompositesAndNullElementWhenSerializingAndDeserializ
return value;
}
+ private List<Character> characterCollection()
+ {
+ List<Character> value = new ArrayList<Character>();
+ value.add( 'Q' );
+ value.add( 'i' );
+ value.add( null );
+ value.add( '4' );
+ value.add( 'j' );
+ return value;
+ }
+
private Collection<Short> shortCollection()
{
Collection<Short> value = new ArrayList<Short>();
@@ -49,6 +49,16 @@ public void before()
@SuppressWarnings( "ProtectedField" )
protected ValueSerialization valueSerialization;
+ @Test
+ public void givenCharacterValueWhenSerializingAndDeserializingExpectEquals()
+ {
+ String serialized = valueSerialization.serialize( 'q' );
+ assertThat( "Serialized", serialized, equalTo( "q" ) );
+
+ Character deserialized = valueSerialization.deserialize( Character.class, serialized );
+ assertThat( "Deserialized", deserialized, equalTo( 'q' ) );
+ }
+
@Test
public void givenEmptyStringValueWhenSerializingAndDeserializingExpectEquals()
{

0 comments on commit 85c1ca2

Please sign in to comment.