You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Daniel Cunha (JIRA)" <ji...@apache.org> on 2014/10/07 03:18:34 UTC
[jira] [Created] (JOHNZON-15) Remove duplicated method on Johzon
Mapper.
Daniel Cunha created JOHNZON-15:
-----------------------------------
Summary: Remove duplicated method on Johzon Mapper.
Key: JOHNZON-15
URL: https://issues.apache.org/jira/browse/JOHNZON-15
Project: Johnzon
Issue Type: Improvement
Reporter: Daniel Cunha
Extracted method to duplicated implementation on writePrimitives:
{code:title=Mapper.java|borderStyle=solid}
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;
}
{code}
{code:title=Mapper.java|borderStyle=solid}
private static JsonGenerator writePrimitives(final JsonGenerator generator, final String key, final Class<?> type, final Object value) {
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;
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)