@Test public void testBatchSerialize_VendorCreate() throws IOException { BatchItemRequest request = new BatchItemRequest(); OutputStream outputStream = new ByteArrayOutputStream(); JsonGenerator generator = factory.createGenerator(outputStream); Vendor vendor = getVendorObject(); JAXBElement element = getJaxBElementObject(vendor); request.setIntuitObject(element); request.setOperation(OperationEnum.CREATE); serializer.serialize(request, generator, null); generator.flush(); String output = outputStream.toString(); Assert.assertEquals(output, "{\"Vendor\":{\"Title\":\"Ms.\",\"GivenName\":\"Penny\",\"MiddleName\":\"Kaley\",\"FamilyName\":\"Cuoco\"},\"operation\":\"create\"}"); }
@Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (StringUtils.hasText(batchItemRequest.getBId())) { jgen.writeFieldName(BID); jgen.writeString(batchItemRequest.getBId()); } if (batchItemRequest.getIntuitObject() != null) { jgen.writeFieldName(batchItemRequest.getIntuitObject().getValue().getClass().getSimpleName()); try { jgen.writeNumber(new JSONSerializer().serialize(batchItemRequest.getIntuitObject())); } catch (SerializationException e) { LOG.error("SerializationException while generating Json for IntuitObject in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (batchItemRequest.getCDCQuery() != null) { jgen.writeFieldName(CDC_QUERY); try { jgen.writeNumber(getCDCQueryJson(batchItemRequest.getCDCQuery())); } catch (Exception e) { LOG.error("SerializationException while generating Json for CDCQuery in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (StringUtils.hasText(batchItemRequest.getQuery())) { jgen.writeFieldName(QUERY); jgen.writeString(batchItemRequest.getQuery()); } if (StringUtils.hasText(batchItemRequest.getReportQuery())) { jgen.writeFieldName(REPORT_QUERY); jgen.writeString(batchItemRequest.getReportQuery()); } if (batchItemRequest.getOperation() != null) { jgen.writeFieldName(OPERATION); jgen.writeString(batchItemRequest.getOperation().value()); } if (StringUtils.hasText(batchItemRequest.getOptionsData())) { jgen.writeFieldName(OPTIONS_DATA); jgen.writeString(batchItemRequest.getOptionsData()); } jgen.writeEndObject(); }
BatchItemRequestSerializer extends JsonSerializer<BatchItemRequest> { @Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (StringUtils.hasText(batchItemRequest.getBId())) { jgen.writeFieldName(BID); jgen.writeString(batchItemRequest.getBId()); } if (batchItemRequest.getIntuitObject() != null) { jgen.writeFieldName(batchItemRequest.getIntuitObject().getValue().getClass().getSimpleName()); try { jgen.writeNumber(new JSONSerializer().serialize(batchItemRequest.getIntuitObject())); } catch (SerializationException e) { LOG.error("SerializationException while generating Json for IntuitObject in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (batchItemRequest.getCDCQuery() != null) { jgen.writeFieldName(CDC_QUERY); try { jgen.writeNumber(getCDCQueryJson(batchItemRequest.getCDCQuery())); } catch (Exception e) { LOG.error("SerializationException while generating Json for CDCQuery in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (StringUtils.hasText(batchItemRequest.getQuery())) { jgen.writeFieldName(QUERY); jgen.writeString(batchItemRequest.getQuery()); } if (StringUtils.hasText(batchItemRequest.getReportQuery())) { jgen.writeFieldName(REPORT_QUERY); jgen.writeString(batchItemRequest.getReportQuery()); } if (batchItemRequest.getOperation() != null) { jgen.writeFieldName(OPERATION); jgen.writeString(batchItemRequest.getOperation().value()); } if (StringUtils.hasText(batchItemRequest.getOptionsData())) { jgen.writeFieldName(OPTIONS_DATA); jgen.writeString(batchItemRequest.getOptionsData()); } jgen.writeEndObject(); } }
BatchItemRequestSerializer extends JsonSerializer<BatchItemRequest> { @Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (StringUtils.hasText(batchItemRequest.getBId())) { jgen.writeFieldName(BID); jgen.writeString(batchItemRequest.getBId()); } if (batchItemRequest.getIntuitObject() != null) { jgen.writeFieldName(batchItemRequest.getIntuitObject().getValue().getClass().getSimpleName()); try { jgen.writeNumber(new JSONSerializer().serialize(batchItemRequest.getIntuitObject())); } catch (SerializationException e) { LOG.error("SerializationException while generating Json for IntuitObject in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (batchItemRequest.getCDCQuery() != null) { jgen.writeFieldName(CDC_QUERY); try { jgen.writeNumber(getCDCQueryJson(batchItemRequest.getCDCQuery())); } catch (Exception e) { LOG.error("SerializationException while generating Json for CDCQuery in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (StringUtils.hasText(batchItemRequest.getQuery())) { jgen.writeFieldName(QUERY); jgen.writeString(batchItemRequest.getQuery()); } if (StringUtils.hasText(batchItemRequest.getReportQuery())) { jgen.writeFieldName(REPORT_QUERY); jgen.writeString(batchItemRequest.getReportQuery()); } if (batchItemRequest.getOperation() != null) { jgen.writeFieldName(OPERATION); jgen.writeString(batchItemRequest.getOperation().value()); } if (StringUtils.hasText(batchItemRequest.getOptionsData())) { jgen.writeFieldName(OPTIONS_DATA); jgen.writeString(batchItemRequest.getOptionsData()); } jgen.writeEndObject(); }  }
BatchItemRequestSerializer extends JsonSerializer<BatchItemRequest> { @Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (StringUtils.hasText(batchItemRequest.getBId())) { jgen.writeFieldName(BID); jgen.writeString(batchItemRequest.getBId()); } if (batchItemRequest.getIntuitObject() != null) { jgen.writeFieldName(batchItemRequest.getIntuitObject().getValue().getClass().getSimpleName()); try { jgen.writeNumber(new JSONSerializer().serialize(batchItemRequest.getIntuitObject())); } catch (SerializationException e) { LOG.error("SerializationException while generating Json for IntuitObject in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (batchItemRequest.getCDCQuery() != null) { jgen.writeFieldName(CDC_QUERY); try { jgen.writeNumber(getCDCQueryJson(batchItemRequest.getCDCQuery())); } catch (Exception e) { LOG.error("SerializationException while generating Json for CDCQuery in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (StringUtils.hasText(batchItemRequest.getQuery())) { jgen.writeFieldName(QUERY); jgen.writeString(batchItemRequest.getQuery()); } if (StringUtils.hasText(batchItemRequest.getReportQuery())) { jgen.writeFieldName(REPORT_QUERY); jgen.writeString(batchItemRequest.getReportQuery()); } if (batchItemRequest.getOperation() != null) { jgen.writeFieldName(OPERATION); jgen.writeString(batchItemRequest.getOperation().value()); } if (StringUtils.hasText(batchItemRequest.getOptionsData())) { jgen.writeFieldName(OPTIONS_DATA); jgen.writeString(batchItemRequest.getOptionsData()); } jgen.writeEndObject(); }  @Override void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider); }
BatchItemRequestSerializer extends JsonSerializer<BatchItemRequest> { @Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); if (StringUtils.hasText(batchItemRequest.getBId())) { jgen.writeFieldName(BID); jgen.writeString(batchItemRequest.getBId()); } if (batchItemRequest.getIntuitObject() != null) { jgen.writeFieldName(batchItemRequest.getIntuitObject().getValue().getClass().getSimpleName()); try { jgen.writeNumber(new JSONSerializer().serialize(batchItemRequest.getIntuitObject())); } catch (SerializationException e) { LOG.error("SerializationException while generating Json for IntuitObject in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (batchItemRequest.getCDCQuery() != null) { jgen.writeFieldName(CDC_QUERY); try { jgen.writeNumber(getCDCQueryJson(batchItemRequest.getCDCQuery())); } catch (Exception e) { LOG.error("SerializationException while generating Json for CDCQuery in BatchItemRequestSerializer.", e); throw new IOException(e); } } if (StringUtils.hasText(batchItemRequest.getQuery())) { jgen.writeFieldName(QUERY); jgen.writeString(batchItemRequest.getQuery()); } if (StringUtils.hasText(batchItemRequest.getReportQuery())) { jgen.writeFieldName(REPORT_QUERY); jgen.writeString(batchItemRequest.getReportQuery()); } if (batchItemRequest.getOperation() != null) { jgen.writeFieldName(OPERATION); jgen.writeString(batchItemRequest.getOperation().value()); } if (StringUtils.hasText(batchItemRequest.getOptionsData())) { jgen.writeFieldName(OPTIONS_DATA); jgen.writeString(batchItemRequest.getOptionsData()); } jgen.writeEndObject(); }  @Override void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider);  }