@Override protected Object extractPayload(org.springframework.amqp.core.Message message) { MessageProperties messageProperties = message.getMessageProperties(); if (this.bean != null) { messageProperties.setTargetBean(this.bean); } if (this.method != null) { messageProperties.setTargetMethod(this.method); if (this.inferredArgumentType != null) { messageProperties.setInferredArgumentType(this.inferredArgumentType); } } return extractMessage(message); }
@Override protected Object extractPayload(org.springframework.amqp.core.Message message) { MessageProperties messageProperties = message.getMessageProperties(); if (this.bean != null) { messageProperties.setTargetBean(this.bean); } if (this.method != null) { messageProperties.setTargetMethod(this.method); if (this.inferredArgumentType != null) { messageProperties.setInferredArgumentType(this.inferredArgumentType); } } return extractMessage(message); }
@Test public void testInferredGenericTypeInfo() throws Exception { byte[] bytes = "[ {\"name\" : \"foo\" } ]".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/json"); messageProperties.setInferredArgumentType((new ParameterizedTypeReference<List<Foo>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo, instanceOf(List.class)); assertThat(((List<?>) foo).get(0), instanceOf(Foo.class)); }
@Test public void testInferredGenericTypeInfo() throws Exception { byte[] bytes = "<root><name>foo</name></root>".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/xml"); messageProperties.setInferredArgumentType((new ParameterizedTypeReference<List<Foo>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo).isInstanceOf(List.class); assertThat(((List<?>) foo).get(0)).isInstanceOf(Foo.class); }
@Test public void testInferredTypeInfo() { byte[] bytes = "{\"name\" : \"foo\" }".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/json"); messageProperties.setInferredArgumentType(Foo.class); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo, instanceOf(Foo.class)); }
@Test public void testInferredTypeInfo() { byte[] bytes = "<root><name>foo</name></root>".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/xml"); messageProperties.setInferredArgumentType(Foo.class); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo).isInstanceOf(Foo.class); }
@Test public void testInferredGenericMap1() { byte[] bytes = "<root><qux><element><foo><name>bar</name></foo></element></qux></root>".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/xml"); messageProperties.setInferredArgumentType( (new ParameterizedTypeReference<Map<String, List<Bar>>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo).isInstanceOf(LinkedHashMap.class); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) foo; assertThat(map.get("qux")).isInstanceOf(List.class); Object row = ((List<?>) map.get("qux")).get(0); assertThat(row).isInstanceOf(Bar.class); assertThat(((Bar) row).getFoo()).isEqualTo(new Foo("bar")); }
@Test public void testInferredGenericMap2() { byte[] bytes = "<root><qux><baz><foo><name>bar</name></foo></baz></qux></root>".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/xml"); messageProperties.setInferredArgumentType( (new ParameterizedTypeReference<Map<String, Map<String, Bar>>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo).isInstanceOf(LinkedHashMap.class); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) foo; assertThat(map.get("qux")).isInstanceOf(Map.class); Object value = ((Map<?, ?>) map.get("qux")).get("baz"); assertThat(value).isInstanceOf(Bar.class); assertThat(((Bar) value).getFoo()).isEqualTo(new Foo("bar")); }
@Test public void testInferredGenericMap1() { byte[] bytes = "{\"qux\" : [ { \"foo\" : { \"name\" : \"bar\" } } ] }".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/json"); messageProperties.setInferredArgumentType( (new ParameterizedTypeReference<Map<String, List<Bar>>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo, instanceOf(LinkedHashMap.class)); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) foo; assertThat(map.get("qux"), instanceOf(List.class)); Object row = ((List<?>) map.get("qux")).get(0); assertThat(row, instanceOf(Bar.class)); assertThat(((Bar) row).getFoo(), equalTo(new Foo("bar"))); }
@Test public void testInferredGenericMap2() { byte[] bytes = "{\"qux\" : { \"baz\" : { \"foo\" : { \"name\" : \"bar\" } } } }".getBytes(); MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("application/json"); messageProperties.setInferredArgumentType( (new ParameterizedTypeReference<Map<String, Map<String, Bar>>>() { }).getType()); Message message = new Message(bytes, messageProperties); Object foo = this.converter.fromMessage(message); assertThat(foo, instanceOf(LinkedHashMap.class)); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) foo; assertThat(map.get("qux"), instanceOf(Map.class)); Object value = ((Map<?, ?>) map.get("qux")).get("baz"); assertThat(value, instanceOf(Bar.class)); assertThat(((Bar) value).getFoo(), equalTo(new Foo("bar"))); }