diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java index dd00729b..f22e5ff2 100644 --- a/src/main/java/org/springframework/hateoas/PagedResources.java +++ b/src/main/java/org/springframework/hateoas/PagedResources.java @@ -29,7 +29,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -@XmlRootElement(name = "entities") +@XmlRootElement(name = "pagedEntities") public class PagedResources extends Resources { public static PagedResources NO_PAGE = new PagedResources(); diff --git a/src/test/java/org/springframework/hateoas/PagedResourcesMarshallingTest.java b/src/test/java/org/springframework/hateoas/PagedResourcesMarshallingTest.java new file mode 100644 index 00000000..0ba6601a --- /dev/null +++ b/src/test/java/org/springframework/hateoas/PagedResourcesMarshallingTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.hateoas; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.Charset; +import java.util.ArrayList; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; + +/** + * Test for marshalling / unmarshalling of {@link PagedResources}. + * + * @author Eric Bottard + */ +public class PagedResourcesMarshallingTest { + + Marshaller marshaller; + Unmarshaller unmarshaller; + + String xmlReference; + PagedResources pagedResources; + + public PagedResourcesMarshallingTest() throws IOException { + xmlReference = readFile(new ClassPathResource("pagedresources.xml")); + } + + @Before + public void setUp() throws Exception { + + JAXBContext context = JAXBContext.newInstance(PagedResources.class); + marshaller = context.createMarshaller(); + unmarshaller = context.createUnmarshaller(); + + pagedResources = new PagedResources(new ArrayList(), null); + } + + /** + * @see #98 + */ + @Test + @SuppressWarnings("unchecked") + public void jaxbUnMarshalling() throws Exception { + + PagedResources actual = (PagedResources) unmarshaller.unmarshal(new StringReader(xmlReference)); + assertThat(actual, is(pagedResources)); + } + + public static class Inner { + + } + + private static String readFile(org.springframework.core.io.Resource resource) throws IOException { + + FileInputStream stream = new FileInputStream(resource.getFile()); + + try { + FileChannel fc = stream.getChannel(); + MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); + return Charset.defaultCharset().decode(bb).toString(); + } finally { + stream.close(); + } + } +} diff --git a/src/test/resources/pagedresources.xml b/src/test/resources/pagedresources.xml new file mode 100644 index 00000000..afa920c5 --- /dev/null +++ b/src/test/resources/pagedresources.xml @@ -0,0 +1 @@ + \ No newline at end of file