Announcement Announcement Module
Collapse
No announcement yet.
Problem with object-to-map-transformer and map-to-object-transformer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with object-to-map-transformer and map-to-object-transformer

    Hello Guys

    I am working with STS 2.6.1 and SI 2.0.4.RELEASE

    I have this POJO

    Code:
    @Component
    public class Cliente implements java.io.Serializable {
    	
    	private static final long serialVersionUID = 1L;
    	
    	private String nombres;
    	private String apellidos;
    	private Integer edad;
    	private Double peso;
    	private BigDecimal credito;
    	private Date fechaNacimiento;
    And I have

    Code:
    <int:object-to-map-transformer 
           input-channel="input"
           output-channel="map" />
    	
    <int:map-to-object-transformer 
          input-channel="map"
          output-channel="output"
          type="com.manuel.jordan.domain.Cliente"
    />
    
    <int:logging-channel-adapter 
          id="logger"
          log-full-message="true"
          level="INFO"
    />
    .....
    According with 6.1.2 Configuring Transformer, I am worry with the follow bold part

    Object-to-Map Transformer

    Spring Integration also provides Object-to-Map and Map-to-Object transformers which utilize the Spring Expression Language (SpEL) to serialize and de-serialize the object graphs. The object hierarchy is introspected to the most primitive types (String, int, etc.). The path to this type is described via SpEL, which becomes the key in the transformed Map. The primitive type becomes the value.
    Because In my Main class I have the follow two situations

    First
    Working with a Map

    Code:
    Map<String, Object> clienteMap = new HashMap<String, Object>();		
    clienteMap.put("nombres", "Manuel");
    clienteMap.put("apellidos","Jordan" );
    clienteMap.put("edad", 30 );
    clienteMap.put("peso", 70.01);
    clienteMap.put("credito", new BigDecimal("150.85") );
    clienteMap.put("fechaNacimiento",  new Date());
    
    logger.info("Before To Send toString(): {} ", clienteMap.toString());
    		
    Message<Map<String, Object>> messageMap = MessageBuilder.withPayload(clienteMap).build();
    input.send(messageMap);
    		
    Message<?> reply = output.receive();
    logger.info("Message Received reply.toString(){}", reply.toString());
    and I got the follow results
    Code:
    2011-07-07 10:22:42,015 INFO [com.manuel.jordan.main.transformers.core.MainTransformCore] - 
    <Before To Send toString(): {peso=70.01, nombres=Manuel, credito=150.85, 
    apellidos=Jordan, edad=30, fechaNacimiento=Thu Jul 07 10:22:42 COT 2011} >
    
    2011-07-07 10:22:42,093 INFO [org.springframework.integration.handler.LoggingHandler] - 
    <[Payload={empty=false}][Headers={timestamp=1310052162093, id=0ee366a1-707d-
    4da0-94b7-757ba2e5e42d}]>
    
    2011-07-07 10:22:42,140 INFO [com.manuel.jordan.main.transformers.core.MainTransformCore] - 
    <Message Received reply.toString()[Payload=
     Cliente 
     nombres=null
     apellidos=null
     edad=null
     peso=null
     credito=null
     fechaNacimiento=null]
    [Headers={timestamp=1310052162140, id=0dfe3f34-e797-4835-897d-57940c0d5f41}]>
    ....
    do realize yourself about the follow

    1) the Map Object is correctly shown before to be sent it to the Channel (first green part)

    2) It was correctly transformed with object-to-map-transformer.
    Yes I know, Map to again to a Map? redundance?
    Yes, I did this only for research purpose, I want see the behaviour. See blue part

    3) But see the second green part, all the properties are null
    when it is transformed with map-to-object-transformer and received from the channel.

    Why? If I am using the attribute
    Code:
    <int:map-to-object-transformer
          input-channel="map"
          output-channel="output"
          type="com.manuel.jordan.domain.Cliente"
    />
    and the
    Code:
    Message<?> reply = output.receive();
    which is a generic object which it should be received after the transformation

    Second

    Now I have the follow problem, if I use

    Code:
    Cliente cliente = new Cliente();		
    cliente.setNombres("Manuel");
    cliente.setApellidos("Jordan");		
    cliente.setEdad(30);		
    cliente.setPeso(70.01);		
    cliente.setCredito(new BigDecimal("150.85"));
    cliente.setFechaNacimiento( new Date());
    
    logger.info("Before to Send toString(): {} ", cliente.toString());
    		
    Message<?> messageAltern01 = MessageBuilder.withPayload(cliente).build();
    input.send(messageAltern01);
    		
    Message<?> replyAltern01 = output.receive();		
    logger.info("Message Received replyAltern01.toString(){}", replyAltern01.toString());
    I got


    Code:
    2011-07-07 10:54:06,937 INFO [com.manuel.jordan.main.transformers.core.MainTransformCore] - 
    <Before to Send toString(): 
     Cliente 
     nombres=Manuel
     apellidos=Jordan
     edad=30
     peso=70.01
     credito=150.85
     fechaNacimiento=Thu Jul 07 10:54:06 COT 2011 >
    
    Exception in thread "main" org.springframework.integration.transformer.MessageTransformationException: failed to transform message
    	at org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:44)
    	at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:67)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:98)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:110)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at com.manuel.jordan.main.transformers.core.MainTransformCore.main(MainTransformCore.java:84)
    Caused by: java.lang.NullPointerException
    	at org.springframework.integration.transformer.ObjectToSpelMapBuilder.buildProperties(ObjectToSpelMapBuilder.java:59)
    	at org.springframework.integration.transformer.ObjectToSpelMapBuilder.processElementValue(ObjectToSpelMapBuilder.java:138)
    	at org.springframework.integration.transformer.ObjectToSpelMapBuilder.buildProperties(ObjectToSpelMapBuilder.java:76)
    	at org.springframework.integration.transformer.ObjectToSpelMapBuilder.buildSpelMap(ObjectToSpelMapBuilder.java:48)
    	at org.springframework.integration.transformer.ObjectToMapTransformer.transformPayload(ObjectToMapTransformer.java:50)
    	at org.springframework.integration.transformer.ObjectToMapTransformer.transformPayload(ObjectToMapTransformer.java:40)
    	at org.springframework.integration.transformer.AbstractPayloadTransformer.doTransform(AbstractPayloadTransformer.java:33)
    ...
    	... 9 more
    I cant see the 9 more messages, but If I comment these lines

    Code:
    Cliente cliente = new Cliente();		
    cliente.setNombres("Manuel");
    cliente.setApellidos("Jordan");		
    cliente.setEdad(30);		
    cliente.setPeso(70.01);		
    /*
    cliente.setCredito(new BigDecimal("150.85"));
    cliente.setFechaNacimiento( new Date());
    */
    I got now

    Code:
    2011-07-07 10:58:52,015 INFO [com.manuel.jordan.main.transformers.core.MainTransformCore] - 
    <Before to Send toString()
     Cliente 
     nombres=Samuel
     apellidos=Elera
     edad=30
     peso=70.01
     credito=null
     fechaNacimiento=null >
    
    2011-07-07 10:58:52,015 INFO [org.springframework.integration.handler.LoggingHandler] - 
    <[Payload={peso=70.01, nombres=Manuel, apellidos=Jordan, edad=30}][Headers=
    {timestamp=1310054332015, id=bb1bb3a5-5b8c-4aa1-a124-1539088f7ff8}]>
    
    2011-07-07 10:58:52,015 INFO [com.manuel.jordan.main.transformers.core.MainTransformCore] - 
    <Message Received replyAltern01.toString()
    [Payload=
     Cliente 
     nombres=Manuel
     apellidos=Jordan
     edad=30
     peso=70.01
     credito=null
     fechaNacimiento=null]
    [Headers={timestamp=1310054332015, id=06c39720-565c-496d-917e-052173124bcc}]>
    do realize yourself about the follow

    1) the Cliente Object is correctly shown before to be sent it to the Channel (first green part), check the null values in red part since I commented two lines

    2) It was correctly transformed with object-to-map-transformer. See blue part, of course not appear the two variables commented

    3) The code work now since I remove the lines related with BigDecimal and Date, thats why my variables are now are null, see red part


    Therefore for each case
    1) Why this behaviour with the Map object? when I receive the object from the channel
    2) Why I cant use BigDecimal and Date, consider if I am working with Hibernate I need reuse my Entity class and these types of variables are very common used. Why this weird behaviour? according with Spring Integration, is not mandatory use a cannonical object and I am free to send any POJO object

    Thanks in advanced

  • #2
    Manuel

    I'll take a look, but in any event you should not be seeing NPE in Spring Integration so that should have to be fixed, so could you file a JIRA for the NPE?

    Comment


    • #3
      Hello Oleg

      I'll take a look, but in any event you should not be seeing NPE in Spring Integration so that should have to be fixed
      I should get a created Cliente object for the case 1 about the Map object
      and
      I should have no problems about BigDecimal and Date transformation, it is a huge problem for production

      so could you file a JIRA for the NPE?
      I created 2 in 1 here
      https://jira.springsource.org/browse/INT-1968

      I hope all goes well

      Best Regards

      Comment

      Working...
      X