Java Code Examples for com.fasterxml.jackson.dataformat.xml.XmlMapper#readValue()

The following examples show how to use com.fasterxml.jackson.dataformat.xml.XmlMapper#readValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlToJsonUnitTest.java    From tutorials with MIT License 8 votes vote down vote up
@Test
public void givenAnXML_whenUseDataBidingToConvertToJSON_thenReturnDataOK() throws IOException{
    String flowerXML = "<Flower><name>Poppy</name><color>RED</color><petals>9</petals></Flower>";

    XmlMapper xmlMapper = new XmlMapper();
    Flower poppy = xmlMapper.readValue(flowerXML, Flower.class);

    assertEquals(poppy.getName(), "Poppy");
    assertEquals(poppy.getColor(), Color.RED);
    assertEquals(poppy.getPetals(), new Integer(9));

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString(poppy);

    assertEquals(json, "{\"name\":\"Poppy\",\"color\":\"RED\",\"petals\":9}");
}
 
Example 2
Source File: XMLSerializeDeserializeUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();

    String xml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
    Person value = xmlMapper.readValue(xml, Person.class);

    assertTrue(value.getAddress()
        .get(0)
        .getCity()
        .equalsIgnoreCase("city1")
        && value.getAddress()
            .get(1)
            .getCity()
            .equalsIgnoreCase("city2"));
}
 
Example 3
Source File: WxUtils.java    From seezoon-framework-all with Apache License 2.0 5 votes vote down vote up
public static TreeMap<String,Object> xml2map(String xml){
	Assert.hasLength(xml,"xml为空");
	XmlMapper xmlMapper = new XmlMapper();
	try {
		TreeMap<String,Object> readValue = xmlMapper.readValue(xml, TreeMap.class);
		return readValue;
	} catch (Exception e) {
		throw new ServiceException(e.getMessage());
	}
}
 
Example 4
Source File: XML.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T parse(byte[] xml, Class<T> valueType) {
	try {

		XmlMapper mapper = newMapper();
		return mapper.readValue(xml, valueType);

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 5
Source File: GetBoundsCommand.java    From map-matching with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Bootstrap bootstrap, Namespace args) {
    XmlMapper xmlMapper = new XmlMapper();
    BBox bbox = BBox.createInverse(false);
    for (File gpxFile : args.<File>getList("gpx")) {
        try {
            Gpx gpx = xmlMapper.readValue(gpxFile, Gpx.class);
            for (Trk trk : gpx.trk) {
                List<Observation> inputGPXEntries = trk.getEntries();
                for (Observation entry : inputGPXEntries) {
                    bbox.update(entry.getPoint().getLat(), entry.getPoint().getLon());
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    System.out.println("bounds: " + bbox);

    // show download only for small areas
    if (bbox.maxLat - bbox.minLat < 0.1 && bbox.maxLon - bbox.minLon < 0.1) {
        double delta = 0.01;
        System.out.println("Get small areas via\n"
                + "wget -O extract.osm 'http://overpass-api.de/api/map?bbox="
                + (bbox.minLon - delta) + "," + (bbox.minLat - delta) + ","
                + (bbox.maxLon + delta) + "," + (bbox.maxLat + delta) + "'");
    }
}
 
Example 6
Source File: BasicSerializableRepository.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public T fromXML(String xml) {
    T obj = null;
    if (StringUtils.isNotBlank(xml)) {
        final XmlMapper mapper = createXMLMapper();
        try {
            obj = mapper.readValue(xml, getDomainClass());
        } catch (IOException e) {
            log.warn("Could not deserialize xml", e);
            obj = null;
        }
    }
    return obj;
}
 
Example 7
Source File: BasicSerializableRepository.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public T fromXML(String xml) {
    T obj = null;
    if (StringUtils.isNotBlank(xml)) {
        final XmlMapper mapper = createXMLMapper();
        try {
            obj = mapper.readValue(xml, getDomainClass());
        } catch (IOException e) {
            log.warn("Could not deserialize xml", e);
            obj = null;
        }
    }
    return obj;
}
 
Example 8
Source File: JacksonTest.java    From weixin-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testXml2Bean() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();
    RefundQueryWrapper refundQueryWrapper =  xmlMapper.readValue(getXml(), RefundQueryWrapper.class);
    Assert.assertNotNull(refundQueryWrapper);
    Assert.assertNotNull(refundQueryWrapper.getRefundQuery());

}
 
Example 9
Source File: AnySetter349Test.java    From weixin-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnwrappedWithAny() throws Exception {
    final XmlMapper mapper = new XmlMapper();
    final String xml = "<xml>\n" +
            "<type>type</type>\n" +
            "<x>10</x>\n" +
            "<y>10</y>\n" +
            "<k1>k1</k1>\n" +
            "<k2>k1</k2>\n" +
            "<k3>k1</k3>\n" +
            "</xml>";

    Bean349 value = mapper.readValue(xml, Bean349.class);
    Assert.assertNotNull(value);
}
 
Example 10
Source File: RefundQueryTest.java    From weixin-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testXml2Bean() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();
    RefundQueryWrapper refundQueryWrapper =  xmlMapper.readValue(getXml(), RefundQueryWrapper.class);
    Assert.assertNotNull(refundQueryWrapper);
    Assert.assertNotNull(refundQueryWrapper.getRefundQuery());
    refundQueryWrapper.ready();
    Assert.assertNotNull(refundQueryWrapper.getRefundQuery().getRefunds());
    Assert.assertEquals(2, refundQueryWrapper.getRefundQuery().getRefunds().size());
}
 
Example 11
Source File: XMLSerializeDeserializeUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenJavaGotFromXmlFile_thenCorrect() throws IOException {
    File file = new File("src/test/resources/simple_bean.xml");
    XmlMapper xmlMapper = new XmlMapper();
    String xml = inputStreamToString(new FileInputStream(file));
    SimpleBean value = xmlMapper.readValue(xml, SimpleBean.class);
    assertTrue(value.getX() == 1 && value.getY() == 2);
}
 
Example 12
Source File: PayUtils.java    From weixin-pay with MIT License 5 votes vote down vote up
/**
 * 
 * @param inputStream request.getInputStream()
 * @return
 */
public static PayNativeInput convertRequest(InputStream inputStream){
	try {
		String content = IOUtils.toString(inputStream);
		
		XmlMapper xmlMapper = new XmlMapper();
		PayNativeInput payNativeInput = xmlMapper.readValue(content, PayNativeInput.class);
		
		return payNativeInput;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 13
Source File: XML.java    From nifi-swagger-client with Apache License 2.0 5 votes vote down vote up
private  <T> T readError(String error, Type returnType) throws ApiException {
    try {
        // Fallback processing when failed to parse XML form response body:
        //   return the response body string directly for the String return type;
        //   parse response body into date or datetime for the Date return type.
        if (returnType.equals(String.class))
            return (T) error;
        XmlMapper xmlMapper = new XmlMapper();
        ErrorResponse value = xmlMapper.readValue(error, ErrorResponse.class);
        throw new ApiException(Integer.valueOf(value.getStatus()), value.getStatusText());
    } catch (NumberFormatException | IOException ea) {
       throw new ApiException(error);
    }
}
 
Example 14
Source File: WxUtils.java    From seezoon-framework-all with Apache License 2.0 5 votes vote down vote up
public static <T> T xmlToBean(String xml, Class<T> clazz) {
	 Assert.hasLength(xml,"xml 为空");
	 XmlMapper xmlMapper = new XmlMapper();
	 xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

	try {
		return xmlMapper.readValue(xml, clazz);
	} catch (IOException e) {
		throw new ServiceException(e.getMessage());
	}
}
 
Example 15
Source File: JobConfigurationSerializationTest.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void xmlWithJson() throws IOException
{
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
    xmlMapper.configure( DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false );

    JobConfiguration jc = xmlMapper.readValue( "<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" +
        "      <jobStatus>SCHEDULED</jobStatus>\n" +
        "      <displayName>Test Analytic</displayName>\n" +
        "      <enabled>true</enabled>\n" +
        "      <leaderOnlyJob>true</leaderOnlyJob>\n" +
        "      <externalAccess>false</externalAccess>\n" +
        "      <jobType>ANALYTICS_TABLE</jobType>\n" +
        "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" +
        "      <favorite>false</favorite>\n" +
        "      <configurable>true</configurable>\n" +
        "      <access>\n" +
        "        <read>true</read>\n" +
        "        <update>true</update>\n" +
        "        <externalize>false</externalize>\n" +
        "        <delete>true</delete>\n" +
        "        <write>true</write>\n" +
        "        <manage>true</manage>\n" +
        "      </access>\n" +
        "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" +
        "      <jobParameters>\n" +
        "        <lastYears>2</lastYears>\n" +
        "        <skipResourceTables>true</skipResourceTables>\n" +
        "        <skipTableTypes>\n" +
        "          <skipTableType>ENROLLMENT</skipTableType>\n" +
        "          <skipTableType>ORG_UNIT_TARGET</skipTableType>\n" +
        "          <skipTableType>VALIDATION_RESULT</skipTableType>\n" +
        "        </skipTableTypes>" +
        "      </jobParameters>\n" +
        "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" +
        "    </jobConfiguration>", JobConfiguration.class );

    Assert.assertEquals( JobStatus.SCHEDULED, jc.getJobStatus() );
    Assert.assertEquals( "Test Analytic", jc.getName() );
    Assert.assertEquals( "Test Analytic", jc.getDisplayName() );
    Assert.assertTrue( jc.isEnabled() );
    Assert.assertTrue( jc.isLeaderOnlyJob() );
    Assert.assertEquals( JobType.ANALYTICS_TABLE, jc.getJobType() );
    Assert.assertNull( jc.getNextExecutionTime() );
    Assert.assertEquals( "0 0 12 ? * MON-FRI", jc.getCronExpression() );

    Assert.assertNotNull( jc.getJobParameters() );
    Assert.assertEquals( (Integer) 2, ( (AnalyticsJobParameters) jc.getJobParameters() ).getLastYears() );
    Assert.assertTrue( ( (AnalyticsJobParameters) jc.getJobParameters() ).isSkipResourceTables() );
    Assert.assertNotNull( ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes() );
    Assert.assertEquals( 3, ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes().size() );
    Assert.assertThat( ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes(), Matchers.hasItems( AnalyticsTableType.ENROLLMENT, AnalyticsTableType.ORG_UNIT_TARGET, AnalyticsTableType.VALIDATION_RESULT ) );
}
 
Example 16
Source File: JobConfigurationSerializationTest.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void xmlWithEmptyArray() throws IOException
{
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
    xmlMapper.configure( DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false );

    JobConfiguration jc = xmlMapper.readValue( "<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" +
        "      <jobStatus>SCHEDULED</jobStatus>\n" +
        "      <displayName>Test Analytic</displayName>\n" +
        "      <enabled>true</enabled>\n" +
        "      <leaderOnlyJob>true</leaderOnlyJob>\n" +
        "      <externalAccess>false</externalAccess>\n" +
        "      <jobType>ANALYTICS_TABLE</jobType>\n" +
        "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" +
        "      <favorite>false</favorite>\n" +
        "      <configurable>true</configurable>\n" +
        "      <access>\n" +
        "        <read>true</read>\n" +
        "        <update>true</update>\n" +
        "        <externalize>false</externalize>\n" +
        "        <delete>true</delete>\n" +
        "        <write>true</write>\n" +
        "        <manage>true</manage>\n" +
        "      </access>\n" +
        "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" +
        "      <jobParameters>\n" +
        "        <lastYears>2</lastYears>\n" +
        "        <skipResourceTables>true</skipResourceTables>\n" +
        "        <skipTableTypes>\n" +
        "        </skipTableTypes>" +
        "      </jobParameters>\n" +
        "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" +
        "    </jobConfiguration>", JobConfiguration.class );

    Assert.assertEquals( "uB9oC4R2nTn", jc.getUid() );
    Assert.assertEquals( JobStatus.SCHEDULED, jc.getJobStatus() );
    Assert.assertEquals( "Test Analytic", jc.getName() );
    Assert.assertEquals( "Test Analytic", jc.getDisplayName() );
    Assert.assertTrue( jc.isEnabled() );
    Assert.assertTrue( jc.isLeaderOnlyJob() );
    Assert.assertEquals( JobType.ANALYTICS_TABLE, jc.getJobType() );
    Assert.assertNull( jc.getNextExecutionTime() );
    Assert.assertEquals( "0 0 12 ? * MON-FRI", jc.getCronExpression() );

    Assert.assertNotNull( jc.getJobParameters() );
    Assert.assertEquals( (Integer) 2, ( (AnalyticsJobParameters) jc.getJobParameters() ).getLastYears() );
    Assert.assertTrue( ( (AnalyticsJobParameters) jc.getJobParameters() ).isSkipResourceTables() );
    Assert.assertNotNull( ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes() );
    Assert.assertEquals( 0, ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes().size() );
}
 
Example 17
Source File: JobConfigurationSerializationTest.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void xmlWithArray() throws IOException
{
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
    xmlMapper.configure( DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false );

    JobConfiguration jc = xmlMapper.readValue( "<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" +
        "      <jobStatus>NONE</jobStatus>\n" +
        "      <displayName>Test Analytic</displayName>\n" +
        "      <enabled>true</enabled>\n" +
        "      <leaderOnlyJob>true</leaderOnlyJob>\n" +
        "      <externalAccess>false</externalAccess>\n" +
        "      <jobType>ANALYTICS_TABLE</jobType>\n" +
        "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" +
        "      <favorite>false</favorite>\n" +
        "      <configurable>true</configurable>\n" +
        "      <access>\n" +
        "        <read>true</read>\n" +
        "        <update>true</update>\n" +
        "        <externalize>false</externalize>\n" +
        "        <delete>true</delete>\n" +
        "        <write>true</write>\n" +
        "        <manage>true</manage>\n" +
        "      </access>\n" +
        "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" +
        "      <jobParameters>\n" +
        "        <lastYears>2</lastYears>\n" +
        "        <skipResourceTables>true</skipResourceTables>\n" +
        "        <skipTableTypes>\n" +
        "          <skipTableType>ENROLLMENT</skipTableType>\n" +
        "          <skipTableType>ORG_UNIT_TARGET</skipTableType>\n" +
        "          <skipTableType>VALIDATION_RESULT</skipTableType>\n" +
        "        </skipTableTypes>" +
        "      </jobParameters>\n" +
        "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" +
        "    </jobConfiguration>", JobConfiguration.class );

    Assert.assertEquals( JobStatus.SCHEDULED, jc.getJobStatus() );
    Assert.assertEquals( "Test Analytic", jc.getDisplayName() );
    Assert.assertTrue( jc.isEnabled() );
    Assert.assertTrue( jc.isLeaderOnlyJob() );
    Assert.assertEquals( JobType.ANALYTICS_TABLE, jc.getJobType() );
    Assert.assertNull( jc.getNextExecutionTime() );
    Assert.assertEquals( "0 0 12 ? * MON-FRI", jc.getCronExpression() );

    Assert.assertNotNull( jc.getJobParameters() );
    Assert.assertEquals( (Integer) 2, ( (AnalyticsJobParameters) jc.getJobParameters() ).getLastYears() );
    Assert.assertTrue( ( (AnalyticsJobParameters) jc.getJobParameters() ).isSkipResourceTables() );
    Assert.assertNotNull( ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes() );
    Assert.assertEquals( 3, ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes().size() );
    Assert.assertThat( ( (AnalyticsJobParameters) jc.getJobParameters() ).getSkipTableTypes(), Matchers.hasItems( AnalyticsTableType.ENROLLMENT, AnalyticsTableType.ORG_UNIT_TARGET, AnalyticsTableType.VALIDATION_RESULT ) );
}
 
Example 18
Source File: MatchCommand.java    From map-matching with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Bootstrap bootstrap, Namespace args) {
    GraphHopperConfig graphHopperConfiguration = new GraphHopperConfig();
    String ghFolder = "graph-cache";
    graphHopperConfiguration.putObject("graph.location", ghFolder);

    String vehicle = args.getString("vehicle");
    if (Helper.isEmpty(vehicle))
        vehicle = EncodingManager.create(new DefaultEncodedValueFactory(), new DefaultFlagEncoderFactory(), ghFolder).fetchEdgeEncoders().get(0).toString();
    // Penalizing inner-link U-turns only works with fastest weighting, since
    // shortest weighting does not apply penalties to unfavored virtual edges.
    String weightingStr = "fastest";
    Profile profile = new Profile(vehicle + "_profile").setVehicle(vehicle).setWeighting(weightingStr).setTurnCosts(false);
    graphHopperConfiguration.setProfiles(Collections.singletonList(profile));
    GraphHopper hopper = new GraphHopperOSM().init(graphHopperConfiguration);
    System.out.println("loading graph from cache");
    hopper.load(graphHopperConfiguration.getString("graph.location", ghFolder));

    PMap hints = new PMap().putObject(MAX_VISITED_NODES, args.get("max_visited_nodes"));
    hints.putObject("profile", profile.getName());
    MapMatching mapMatching = new MapMatching(hopper, hints);
    mapMatching.setTransitionProbabilityBeta(args.getDouble("transition_probability_beta"));
    mapMatching.setMeasurementErrorSigma(args.getInt("gps_accuracy"));

    StopWatch importSW = new StopWatch();
    StopWatch matchSW = new StopWatch();

    Translation tr = new TranslationMap().doImport().getWithFallBack(Helper.getLocale(args.getString("instructions")));
    final boolean withRoute = !args.getString("instructions").isEmpty();
    XmlMapper xmlMapper = new XmlMapper();

    Weighting weighting = hopper.createWeighting(hopper.getProfiles().get(0), hints);

    for (File gpxFile : args.<File>getList("gpx")) {
        try {
            importSW.start();
            Gpx gpx = xmlMapper.readValue(gpxFile, Gpx.class);
            if (gpx.trk == null) {
                throw new IllegalArgumentException("No tracks found in GPX document. Are you using waypoints or routes instead?");
            }
            if (gpx.trk.size() > 1) {
                throw new IllegalArgumentException("GPX documents with multiple tracks not supported yet.");
            }
            List<Observation> measurements = gpx.trk.get(0).getEntries();
            importSW.stop();
            matchSW.start();
            MatchResult mr = mapMatching.doWork(measurements);
            matchSW.stop();
            System.out.println(gpxFile);
            System.out.println("\tmatches:\t" + mr.getEdgeMatches().size() + ", gps entries:" + measurements.size());
            System.out.println("\tgpx length:\t" + (float) mr.getGpxEntriesLength() + " vs " + (float) mr.getMatchLength());

            String outFile = gpxFile.getAbsolutePath() + ".res.gpx";
            System.out.println("\texport results to:" + outFile);

            ResponsePath responsePath = new ResponsePath();
            new PathMerger(mr.getGraph(), weighting).
                    doWork(responsePath, Collections.singletonList(mr.getMergedPath()), hopper.getEncodingManager(), tr);
            if (responsePath.hasErrors()) {
                System.err.println("Problem with file " + gpxFile + ", " + responsePath.getErrors());
                continue;
            }

            try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) {
                long time = gpx.trk.get(0).getStartTime()
                        .map(Date::getTime)
                        .orElse(System.currentTimeMillis());
                writer.append(GpxFromInstructions.createGPX(responsePath.getInstructions(), gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", time, hopper.hasElevation(), withRoute, true, false, Constants.VERSION, tr));
            }
        } catch (Exception ex) {
            importSW.stop();
            matchSW.stop();
            System.err.println("Problem with file " + gpxFile);
            ex.printStackTrace(System.err);
        }
    }
    System.out.println("gps import took:" + importSW.getSeconds() + "s, match took: " + matchSW.getSeconds());
}
 
Example 19
Source File: XMLSerializeDeserializeUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();
    SimpleBeanForCapitalizedFields value = xmlMapper.readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>", SimpleBeanForCapitalizedFields.class);
    assertTrue(value.getX() == 1 && value.getY() == 2);
}
 
Example 20
Source File: XMLSerializeDeserializeUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenJavaGotFromXmlStr_thenCorrect() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();
    SimpleBean value = xmlMapper.readValue("<SimpleBean><x>1</x><y>2</y></SimpleBean>", SimpleBean.class);
    assertTrue(value.getX() == 1 && value.getY() == 2);
}