johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Cunha <daniels...@gmail.com>
Subject Re: johnzon-mapper
Date Tue, 07 Oct 2014 01:50:25 GMT
Hi again,

sorry, I forgot to run test and this patch broke all. :(
I didn't understand because has different process for same type.

On Mon, Oct 6, 2014 at 10:27 PM, Daniel Cunha <danielsoro@gmail.com> wrote:

> 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 <danielsoro@gmail.com> 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
>



-- 
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message