JsonMapper implements DocumentBuilder<Patent> { public JsonObject buildJson(Patent patent) { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("patentCorpus", patent.getPatentCorpus().toString()); builder.add("patentType", patent.getPatentType().toString()); builder.add("productionDate", mapDate(patent.getDateProduced())); builder.add("publishedDate", mapDate(patent.getDatePublished())); builder.add("documentId", mapDocumentId(patent.getDocumentId(), true)); builder.add("applicationId", mapDocumentId(patent.getApplicationId(), false)); builder.add("priorityIds", mapDocumentIds(patent.getPriorityIds())); builder.add("priorityIds_tokens", mapDocumentIdVariations(patent.getPriorityIds())); builder.add("relatedIds", mapDocIds(patent.getRelationIds())); builder.add("relatedIds_tokens", mapDocumentIdVariations(patent.getRelationIds())); builder.add("otherIds", mapDocIds(patent.getOtherIds())); builder.add("otherIds_tokens", mapDocumentIdVariations(patent.getOtherIds())); builder.add("agent", mapAgent(patent.getAgent())); builder.add("applicant", mapApplicant(patent.getApplicants())); builder.add("inventors", mapInventors(patent.getInventors())); builder.add("assignees", mapAssignees(patent.getAssignee())); builder.add("examiners", mapExaminers(patent.getExaminers())); JsonObjectBuilder titleObj = Json.createObjectBuilder(); titleObj.add("raw", valueOrEmpty(patent.getTitle())); titleObj.add("normalized", valueOrEmpty(StringCaseUtil.toTitleCase(patent.getTitle()))); builder.add("title", titleObj); builder.add("abstract", mapAbstract(patent.getAbstract())); builder.add("description", mapDescription(patent.getDescription())); builder.add("claims", mapClaims(patent.getClaims())); builder.add("citations", mapCitations(patent.getCitations())); builder.add("classification", mapClassifications(patent.getClassification())); builder.add("search_classification", mapClassifications(patent.getSearchClassification())); return builder.build(); } JsonMapper(boolean pretty, boolean base64); @Override void write(Patent patent, Writer writer); JsonObject buildJson(Patent patent); String getPrettyPrint(JsonObject jsonObject);  }
@Test public void buildJsonTest() throws InvalidDataException, IOException { FormattedText textParserNormalizer = new FormattedText(); DocumentId docId = new DocumentId(CountryCode.US, "123456789"); PatentGranted patent = new PatentGranted(docId, PatentType.UTILITY); patent.setDateProduced(new DocumentDate("20160101")); patent.setDatePublished(new DocumentDate("20160202")); patent.setInventor( Arrays.asList(new Inventor(new NamePerson("Bob", "Inventee"), new Address("123 Main St", "Alexandria", "VA", "22314", CountryCode.US)) ) ); patent.setAssignee( Arrays.asList(new Assignee(new NameOrg("Inventee Inc."), new Address("123 Main St", "Alexandria", "VA", "22314", CountryCode.US)) )); patent.setTitle("Test Patent"); patent.setAbstract(new Abstract("This is the Abstract Section.", textParserNormalizer)); Description desc = new Description(); desc.addSection(new DescriptionSection(DescSection.DRAWING_DESC, "Drawing Desc Text", textParserNormalizer)); desc.addSection(new DescriptionSection(DescSection.REL_APP_DESC, "Rell App Desc Text", textParserNormalizer)); desc.addSection(new DescriptionSection(DescSection.BRIEF_SUMMARY, "Brief Summar Desc Text", textParserNormalizer)); desc.addSection(new DescriptionSection(DescSection.DETAILED_DESC, "Detailed Description Text", textParserNormalizer)); patent.setDescription(desc); JsonMapper json = new JsonMapper(false, false); JsonObject jsonObj = json.buildJson(patent); }