Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-15

Remove duplicated method on Johzon Mapper.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.2-incubating
    • Mapper
    • None

    Description

      Extracted method to duplicated implementation on writePrimitives:

      Mapper.java
      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;
          }
      
      Mapper.java
      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;
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            danielsoro Daniel Cunha
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: