JacksonProvider implements ContextResolver<ObjectMapper> { @Override public ObjectMapper getContext(Class<?> type) { return mapper; } JacksonProvider(); @Override ObjectMapper getContext(Class<?> type);  }
@Test public void testDublinCoreRecord() throws Exception { ObjectMapper om = new JacksonProvider().getContext(DublinCoreRecord.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); URL resource = JacksonProviderTest.class.getResource("dc_test.xml"); assertNotNull(resource); OaiDcType dc = JAXB.unmarshal(resource, OaiDcType.class); DublinCoreRecord dr = new DublinCoreRecord(dc, System.currentTimeMillis(), "uuid:1"); String toJson = om.writeValueAsString(dr); DublinCoreRecord ndr = om.readValue(toJson, DublinCoreRecord.class); assertEquals(dr.getBatchId(), ndr.getBatchId()); assertEquals(dr.getPid(), ndr.getPid()); assertEquals(dr.getTimestamp(), ndr.getTimestamp()); assertEquals(dr.getDc().getIdentifiers(), ndr.getDc().getIdentifiers()); assertEquals(dr.getDc().getTitles(), ndr.getDc().getTitles()); assertEquals(dr.getDc().getCreators(), ndr.getDc().getCreators()); StringWriter toXml = new StringWriter(); DcUtils.marshal(new StreamResult(toXml), ndr.getDc(), true); toXml.flush(); }
@Test public void testMix() throws Exception { ObjectMapper om = new JacksonProvider().getContext(MixType.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); Mix mix = new Mix(); ScannerCapture scanner = new ScannerCapture(); scanner.setScannerManufacturer(MixUtils.stringType("ScannerManufacturer")); ImageCaptureMetadataType imageCaptureMetadata = new ImageCaptureMetadataType(); imageCaptureMetadata.setScannerCapture(scanner); mix.setImageCaptureMetadata(imageCaptureMetadata); String toJson = om.writeValueAsString(mix); Mix result = om.readValue(toJson, Mix.class); assertNotNull(result); assertEquals("ScannerManufacturer", result.getImageCaptureMetadata().getScannerCapture().getScannerManufacturer().getValue()); }
@Test public void testBdmModsDefinition() throws Exception { String toJson = "{\"BdmModsWrapper\":{\n" + " \"mods\":{\n" + " \"identifier\":{\n" + " \"value\":\"8232b78c-345b-40ae-9dc0-17bbb101d304\", \n" + " \"type\":\"uuid\"\n" + " }, \n" + " \"version\":\"3.5\", \n" + " \"relatedItem\":{\n" + " \"part\":{\n" + " \"extent\":{\n" + " \"start\":{\n" + " \"value\":\"1\"\n" + " }, \n" + " \"end\":{\n" + " \"value\":\"2\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }, \n" + " \"reviewed\":true\n" + "}}"; ObjectMapper om = new JacksonProvider().getContext(BdmModsWrapper.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); BdmModsWrapper result = om.readValue(toJson, BdmModsWrapper.class); assertNotNull(result); ModsDefinition resultMods = result.getMods(); assertNotNull(resultMods); String toXml = ModsUtils.toXml(resultMods, true); IdentifierDefinition resultPid = resultMods.getIdentifier().get(0); assertEquals(toXml, "uuid", resultPid.getType()); assertEquals(toXml, "8232b78c-345b-40ae-9dc0-17bbb101d304", resultPid.getValue()); assertFalse(toXml, resultMods.getRelatedItem().isEmpty()); assertEquals(toXml, "1", resultMods.getRelatedItem().get(0).getPart().get(0).getExtent().get(0).getStart().getValue()); }
@Test public void testModsDefinition() throws Exception { ObjectMapper om = new JacksonProvider().getContext(ModsWrapper.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); ModsDefinition mods = ModsStreamEditor.defaultMods("uuid:test"); String toJson = om.writeValueAsString(new ModsWrapper(mods)); ModsWrapper result = om.readValue(toJson, ModsWrapper.class); assertNotNull(result); ModsDefinition resultMods = result.getMods(); assertNotNull(resultMods); IdentifierDefinition resultPid = resultMods.getIdentifier().get(0); assertEquals("uuid", resultPid.getType()); assertEquals("test", resultPid.getValue()); }
@Test public void testNsesss2WrappedInternalDocument() throws Exception { ObjectMapper om = new JacksonProvider().getContext(DesObjectWrapper.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); Dokument nsesss = NsesssUtils.defaultInternalDokument(); String toJson = om.writeValueAsString(new DesObjectWrapper(DesMetadataHandler.mapToJson(nsesss))); DesObjectWrapper result = om.readValue(toJson, DesObjectWrapper.class); assertNotNull(result); assertNotNull(result.getDokument()); }
@Test public void testNsesss2WrappedSpis() throws Exception { ObjectMapper om = new JacksonProvider().getContext(Spis.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); Spis spis = NsesssUtils.defaultSpis(); String toJson = om.writeValueAsString(new DesObjectWrapper(spis)); DesObjectWrapper wrapper = om.readValue(toJson, DesObjectWrapper.class); assertNotNull(wrapper); Spis result = wrapper.getSpis(); assertNotNull(result); assertEquals("ERMS", result.getEvidencniUdaje().getEvidence().getNazevEvidenceDokumentu()); assertEquals(TZpusobVyrizeni.VYŘÍZENÍ_DOKUMENTEM, result.getEvidencniUdaje().getVyrizeniUzavreni().getZpusob()); assertEquals("Vyplývá ze spisového plánu organizace", result.getEvidencniUdaje().getVyrazovani().getSkartacniRezim().getOduvodneni()); assertEquals("Uzavření spisu", result.getEvidencniUdaje().getVyrazovani().getSkartacniRezim().getSpousteciUdalost()); assertEquals(TLogicky.ANO, result.getEvidencniUdaje().getManipulace().getAnalogovyDokument().ANO); }
@Test public void testReadNsesss2WrappedSpis() throws Exception { String toJson = "{ \"Spis\":{ \"EvidencniUdaje\":{ \"Identifikace\":{ \"Identifikator\":[ { \"value\":\"\", \"zdroj\":\"ERMS\" } ] }, \"Popis\":{ \"Nazev\":\"Název\", \"KlicovaSlova\":{ \"KlicoveSlovo\":[ \"slovo2\" ] } }, \"Evidence\":{ \"NazevEvidenceDokumentu\":\"ERMS\" }, \"Puvod\":{ \"DatumVytvoreni\":{ \"value\":\"2013-12-31T23:00:00.000+0000\" } }, \"VyrizeniUzavreni\":{ \"Zpusob\":\"vyřízení dokumentem\" }, \"Vyrazovani\":{ \"SkartacniRezim\":{ \"Oduvodneni\":\"Vyplývá ze spisového plánu organizace\", \"SkartacniLhuta\":1, \"SpousteciUdalost\":\"Uzavření spisu\" } }, \"Manipulace\":{ \"AnalogovyDokument\":\"ano\" } }, \"ID\":\"1\" }}"; ObjectMapper om = new JacksonProvider().getContext(DesObjectWrapper.class); DesObjectWrapper result = om.readValue(toJson, DesObjectWrapper.class); assertNotNull(result.getSpis()); }
@Test public void testNomenclatureAsValueMap() throws Exception { Nomenclatures n = new Nomenclatures(); n.setRecCls(new RecCls()); List<RecCl> recCls = n.getRecCls().getRecCl(); RecCl recCl = new RecCl(); recCl.setFullyQcc("FullyQcc"); recCls.add(recCl); DesaServices desaServices = new DesaServices(null); List<ValueMap> valueMap = desaServices.getValueMap(n, "test"); SmartGwtResponse<ValueMap> sgr = new SmartGwtResponse<ValueMap>(valueMap); ObjectMapper om = new JacksonProvider().getContext(SmartGwtResponse.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); String toJson = om.writeValueAsString(sgr); assertTrue(toJson.contains("\"data\":[{\"mapId\":\"test.rec-cl\",\"values\":[{\"fullyQcc\":\"FullyQcc\"}]}]}")); }