Hi folks, I created a issue to that and made a patch: https://issues.apache.org/jira/browse/JOHNZON-15
On Mon, Oct 6, 2014 at 9:34 PM, Daniel Cunha <[email protected]> wrote: > Hi folks, > > Here short and byte types is processed with your real type. > > https://github.com/apache/incubator-johnzon/blob/master/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java#L89 > > private static JsonGenerator writePrimitives(final JsonGenerator generator, > final Object value) { > if (value == null) { > return null; // fake a write > } > > final Class<?> type = value.getClass(); > if (type == String.class) { > return generator.write(value.toString()); > } else if (type == long.class || type == Long.class) { > return generator.write(Long.class.cast(value).longValue()); > } else if (type == int.class || type == Integer.class) { > return generator.write(Integer.class.cast(value).intValue()); > } else if (type == double.class || type == Double.class > || type == float.class || type == Float.class) { > return generator.write(Number.class.cast(value).doubleValue()); > } else if (type == boolean.class || type == Boolean.class) { > return generator.write(Boolean.class.cast(value).booleanValue()); > } else if (type == BigDecimal.class) { > return generator.write(BigDecimal.class.cast(value)); > } else if (type == BigInteger.class) { > return generator.write(BigInteger.class.cast(value)); > } else if (type == short.class || type == Short.class) { > return generator.write(Short.class.cast(value).shortValue()); > } else if (type == char.class || type == Character.class) { > return generator.write(Character.class.cast(value).toString()); > } else if (type == byte.class || type == Byte.class) { > return generator.write(Byte.class.cast(value).byteValue()); > } > return null; > } > > and here is processed with Number: > > https://github.com/apache/incubator-johnzon/blob/master/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java#L120 > > if (type == String.class) { > return generator.write(key, value.toString()); > } else if (type == long.class || type == Long.class) { > return generator.write(key, Long.class.cast(value).longValue()); > } else if (type == int.class || type == Integer.class > || type == byte.class || type == Byte.class > || type == short.class || type == Short.class) { > return generator.write(key, Number.class.cast(value).intValue()); > } else if (type == double.class || type == Double.class > || type == float.class || type == Float.class) { > return generator.write(key, > Number.class.cast(value).doubleValue()); > } else if (type == boolean.class || type == Boolean.class) { > return generator.write(key, > Boolean.class.cast(value).booleanValue()); > } else if (type == BigDecimal.class) { > return generator.write(key, BigDecimal.class.cast(value)); > } else if (type == BigInteger.class) { > return generator.write(key, BigInteger.class.cast(value)); > } else if (type == char.class || type == Character.class) { > return generator.write(key, > Character.class.cast(value).toString()); > } > return generator; > > Why!? > It seem duplicate codes. > > -- > Daniel Cunha (soro) <http://www.cejug.net> > Blog: http://www.danielsoro.com.br > Twitter: https://twitter.com/dvlc_ > GitHub: https://github.com/danielsoro > LinkedIn: http://www.linkedin.com/in/danielvlcunha > -- Daniel Cunha (soro) <http://www.cejug.net> Blog: http://www.danielsoro.com.br Twitter: https://twitter.com/dvlc_ GitHub: https://github.com/danielsoro LinkedIn: http://www.linkedin.com/in/danielvlcunha
