public InvoiceLineItem deserialize()

in src/main/java/com/microsoft/store/partnercenter/utils/InvoiceLineItemDeserializer.java [40:93]


    public InvoiceLineItem deserialize(JsonParser parser, DeserializationContext ctxt) 
      throws IOException, JsonProcessingException 
    {
        ObjectMapper mapper = (ObjectMapper)parser.getCodec();
        ObjectReader reader = null; 
        JsonNode jsonNode = parser.readValueAsTree();
        Object target = null;
        String billingProvider = jsonNode.get("billingProvider").textValue();
        String invoiceLineItemType = jsonNode.get("invoiceLineItemType").textValue();

        if (invoiceLineItemType.equals("usage_line_items"))
        {
            if (billingProvider.equalsIgnoreCase(BillingProvider.AZURE.getValue()))
            {
                reader = mapper.readerFor(DailyUsageLineItem.class);
            }
            else if(billingProvider.equalsIgnoreCase(BillingProvider.MARKETPLACE.getValue()))
            {
                reader = mapper.readerFor(DailyRatedUsageLineItem.class);
            }
        }
        else if (invoiceLineItemType.equals("billing_line_items"))
        {
            if (billingProvider.equalsIgnoreCase(BillingProvider.AZURE.getValue()))
            {
                reader = mapper.readerFor(UsageBasedLineItem.class);
            }
            else if (billingProvider.equalsIgnoreCase(BillingProvider.OFFICE.getValue()))
            {
                reader = mapper.readerFor(LicenseBasedLineItem.class);
            }
            else if (billingProvider.equalsIgnoreCase(BillingProvider.ONE_TIME.getValue()))
            {
                reader = mapper.readerFor(OneTimeInvoiceLineItem.class);
            }
            else if (billingProvider.equalsIgnoreCase(BillingProvider.ALL.getValue()))
            {
                reader = mapper.readerFor(OneTimeInvoiceLineItem.class);
            }  
        }
        else
        {
            throw new IOException(MessageFormat.format("InvoiceLineItemConverter cannot deserialize invoice line items with type {0}", invoiceLineItemType));
        }
        
        if (reader == null)
        {
            throw new IOException(MessageFormat.format("InvoiceLineItemConverter cannot deserialize invoice line items with type {0} and billing provider: {1}", invoiceLineItemType, billingProvider));
        }

        target = reader.readValue(jsonNode);

        return (InvoiceLineItem)target;
    }