@Test public void testSerialize_null() throws Exception { String str = jsonObj.serialize(null); Assert.assertNull(str); }
@SuppressWarnings("unchecked") public <T> String serialize(T object) throws SerializationException { if (object == null) { return null; } ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); mapper.setAnnotationIntrospector(pair); mapper.setSerializationInclusion(Include.NON_NULL); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); testModule.addSerializer(BatchItemRequest.class, new BatchItemRequestSerializer()); mapper.registerModule(testModule); testModule = new SimpleModule("RecurringTransaction", new Version(1, 0, 0, null)); testModule.addSerializer(RecurringTransaction.class, new RecurringTransactionSerializer()); mapper.registerModule(testModule); String json = null; try { if(object instanceof TaxService) { json = mapper.writeValueAsString(((TaxService) object)); } else { json = mapper.writeValueAsString(((JAXBElement<T>) object).getValue()); } } catch (Exception e) { LOG.error("Exception while json serialize", e); throw new SerializationException(e); } return json; }
JSONSerializer implements IEntitySerializer { @SuppressWarnings("unchecked") public <T> String serialize(T object) throws SerializationException { if (object == null) { return null; } ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); mapper.setAnnotationIntrospector(pair); mapper.setSerializationInclusion(Include.NON_NULL); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); testModule.addSerializer(BatchItemRequest.class, new BatchItemRequestSerializer()); mapper.registerModule(testModule); testModule = new SimpleModule("RecurringTransaction", new Version(1, 0, 0, null)); testModule.addSerializer(RecurringTransaction.class, new RecurringTransactionSerializer()); mapper.registerModule(testModule); String json = null; try { if(object instanceof TaxService) { json = mapper.writeValueAsString(((TaxService) object)); } else { json = mapper.writeValueAsString(((JAXBElement<T>) object).getValue()); } } catch (Exception e) { LOG.error("Exception while json serialize", e); throw new SerializationException(e); } return json; } }
JSONSerializer implements IEntitySerializer { @SuppressWarnings("unchecked") public <T> String serialize(T object) throws SerializationException { if (object == null) { return null; } ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); mapper.setAnnotationIntrospector(pair); mapper.setSerializationInclusion(Include.NON_NULL); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); testModule.addSerializer(BatchItemRequest.class, new BatchItemRequestSerializer()); mapper.registerModule(testModule); testModule = new SimpleModule("RecurringTransaction", new Version(1, 0, 0, null)); testModule.addSerializer(RecurringTransaction.class, new RecurringTransactionSerializer()); mapper.registerModule(testModule); String json = null; try { if(object instanceof TaxService) { json = mapper.writeValueAsString(((TaxService) object)); } else { json = mapper.writeValueAsString(((JAXBElement<T>) object).getValue()); } } catch (Exception e) { LOG.error("Exception while json serialize", e); throw new SerializationException(e); } return json; }  }
JSONSerializer implements IEntitySerializer { @SuppressWarnings("unchecked") public <T> String serialize(T object) throws SerializationException { if (object == null) { return null; } ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); mapper.setAnnotationIntrospector(pair); mapper.setSerializationInclusion(Include.NON_NULL); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); testModule.addSerializer(BatchItemRequest.class, new BatchItemRequestSerializer()); mapper.registerModule(testModule); testModule = new SimpleModule("RecurringTransaction", new Version(1, 0, 0, null)); testModule.addSerializer(RecurringTransaction.class, new RecurringTransactionSerializer()); mapper.registerModule(testModule); String json = null; try { if(object instanceof TaxService) { json = mapper.writeValueAsString(((TaxService) object)); } else { json = mapper.writeValueAsString(((JAXBElement<T>) object).getValue()); } } catch (Exception e) { LOG.error("Exception while json serialize", e); throw new SerializationException(e); } return json; }  @SuppressWarnings("unchecked") String serialize(T object); Response deserialize(String json, Class<?> cl); @Override Response deserializeEntitlements(String decompressedData, Class<EntitlementsResponse> cl); }
JSONSerializer implements IEntitySerializer { @SuppressWarnings("unchecked") public <T> String serialize(T object) throws SerializationException { if (object == null) { return null; } ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); mapper.setAnnotationIntrospector(pair); mapper.setSerializationInclusion(Include.NON_NULL); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); testModule.addSerializer(BatchItemRequest.class, new BatchItemRequestSerializer()); mapper.registerModule(testModule); testModule = new SimpleModule("RecurringTransaction", new Version(1, 0, 0, null)); testModule.addSerializer(RecurringTransaction.class, new RecurringTransactionSerializer()); mapper.registerModule(testModule); String json = null; try { if(object instanceof TaxService) { json = mapper.writeValueAsString(((TaxService) object)); } else { json = mapper.writeValueAsString(((JAXBElement<T>) object).getValue()); } } catch (Exception e) { LOG.error("Exception while json serialize", e); throw new SerializationException(e); } return json; }  @SuppressWarnings("unchecked") String serialize(T object); Response deserialize(String json, Class<?> cl); @Override Response deserializeEntitlements(String decompressedData, Class<EntitlementsResponse> cl);  }