@@ -780,4 +780,75 @@ public void parserShouldReadStrAsBin()
780780 assertEquals ("foo" , binKeyPojo .s );
781781 assertArrayEquals ("bar" .getBytes (), binKeyPojo .b );
782782 }
783+
784+ // Test deserializers that parse a string as a number.
785+ // Actually, com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseInteger() takes care of it.
786+
787+ @ Test
788+ public void deserializeStringAsInteger ()
789+ throws IOException
790+ {
791+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
792+ MessagePack .newDefaultPacker (out ).packString (String .valueOf (Integer .MAX_VALUE )).close ();
793+
794+ Integer v = objectMapper .readValue (out .toByteArray (), Integer .class );
795+ assertThat (v , is (Integer .MAX_VALUE ));
796+ }
797+
798+ @ Test
799+ public void deserializeStringAsLong ()
800+ throws IOException
801+ {
802+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
803+ MessagePack .newDefaultPacker (out ).packString (String .valueOf (Long .MIN_VALUE )).close ();
804+
805+ Long v = objectMapper .readValue (out .toByteArray (), Long .class );
806+ assertThat (v , is (Long .MIN_VALUE ));
807+ }
808+
809+ @ Test
810+ public void deserializeStringAsFloat ()
811+ throws IOException
812+ {
813+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
814+ MessagePack .newDefaultPacker (out ).packString (String .valueOf (Float .MAX_VALUE )).close ();
815+
816+ Float v = objectMapper .readValue (out .toByteArray (), Float .class );
817+ assertThat (v , is (Float .MAX_VALUE ));
818+ }
819+
820+ @ Test
821+ public void deserializeStringAsDouble ()
822+ throws IOException
823+ {
824+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
825+ MessagePack .newDefaultPacker (out ).packString (String .valueOf (Double .MIN_VALUE )).close ();
826+
827+ Double v = objectMapper .readValue (out .toByteArray (), Double .class );
828+ assertThat (v , is (Double .MIN_VALUE ));
829+ }
830+
831+ @ Test
832+ public void deserializeStringAsBigInteger ()
833+ throws IOException
834+ {
835+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
836+ BigInteger bi = BigInteger .valueOf (Long .MAX_VALUE ).add (BigInteger .ONE );
837+ MessagePack .newDefaultPacker (out ).packString (bi .toString ()).close ();
838+
839+ BigInteger v = objectMapper .readValue (out .toByteArray (), BigInteger .class );
840+ assertThat (v , is (bi ));
841+ }
842+
843+ @ Test
844+ public void deserializeStringAsBigDecimal ()
845+ throws IOException
846+ {
847+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
848+ BigDecimal bd = BigDecimal .valueOf (Double .MAX_VALUE );
849+ MessagePack .newDefaultPacker (out ).packString (bd .toString ()).close ();
850+
851+ BigDecimal v = objectMapper .readValue (out .toByteArray (), BigDecimal .class );
852+ assertThat (v , is (bd ));
853+ }
783854}
0 commit comments