@Test public void shouldBeAbleToDeserializeADog() throws Exception { InputStream stream = new ByteArrayInputStream("<dog><name>Brutus</name><age>7</age></dog>".getBytes()); when(provider.parameterNamesFor(bark.getMethod())).thenReturn(new String[] {"dog"}); Object[] deserialized = deserializer.deserialize(stream, bark); assertThat(deserialized.length, is(1)); assertThat(deserialized[0], is(instanceOf(Dog.class))); Dog dog = (Dog) deserialized[0]; assertThat(dog.name, is("Brutus")); assertThat(dog.age, is(7)); }
public Object[] deserialize(InputStream inputStream, ResourceMethod method) { Method javaMethod = method.getMethod(); Class<?>[] types = javaMethod.getParameterTypes(); if (types.length == 0) { throw new IllegalArgumentException("Methods that consumes xml must receive just one argument: the xml root element"); } XStream xStream = getConfiguredXStream(javaMethod, types); Object[] params = new Object[types.length]; chooseParam(types, params, xStream.fromXML(inputStream)); return params; }
XStreamXMLDeserializer implements XMLDeserializer { public Object[] deserialize(InputStream inputStream, ResourceMethod method) { Method javaMethod = method.getMethod(); Class<?>[] types = javaMethod.getParameterTypes(); if (types.length == 0) { throw new IllegalArgumentException("Methods that consumes xml must receive just one argument: the xml root element"); } XStream xStream = getConfiguredXStream(javaMethod, types); Object[] params = new Object[types.length]; chooseParam(types, params, xStream.fromXML(inputStream)); return params; } }
XStreamXMLDeserializer implements XMLDeserializer { public Object[] deserialize(InputStream inputStream, ResourceMethod method) { Method javaMethod = method.getMethod(); Class<?>[] types = javaMethod.getParameterTypes(); if (types.length == 0) { throw new IllegalArgumentException("Methods that consumes xml must receive just one argument: the xml root element"); } XStream xStream = getConfiguredXStream(javaMethod, types); Object[] params = new Object[types.length]; chooseParam(types, params, xStream.fromXML(inputStream)); return params; } XStreamXMLDeserializer(ParameterNameProvider provider, XStreamBuilder builder); }
XStreamXMLDeserializer implements XMLDeserializer { public Object[] deserialize(InputStream inputStream, ResourceMethod method) { Method javaMethod = method.getMethod(); Class<?>[] types = javaMethod.getParameterTypes(); if (types.length == 0) { throw new IllegalArgumentException("Methods that consumes xml must receive just one argument: the xml root element"); } XStream xStream = getConfiguredXStream(javaMethod, types); Object[] params = new Object[types.length]; chooseParam(types, params, xStream.fromXML(inputStream)); return params; } XStreamXMLDeserializer(ParameterNameProvider provider, XStreamBuilder builder); Object[] deserialize(InputStream inputStream, ResourceMethod method); XStream getConfiguredXStream(Method javaMethod, Class<?>[] types); }
XStreamXMLDeserializer implements XMLDeserializer { public Object[] deserialize(InputStream inputStream, ResourceMethod method) { Method javaMethod = method.getMethod(); Class<?>[] types = javaMethod.getParameterTypes(); if (types.length == 0) { throw new IllegalArgumentException("Methods that consumes xml must receive just one argument: the xml root element"); } XStream xStream = getConfiguredXStream(javaMethod, types); Object[] params = new Object[types.length]; chooseParam(types, params, xStream.fromXML(inputStream)); return params; } XStreamXMLDeserializer(ParameterNameProvider provider, XStreamBuilder builder); Object[] deserialize(InputStream inputStream, ResourceMethod method); XStream getConfiguredXStream(Method javaMethod, Class<?>[] types);  }