Apache Camel and Json



  • I want to deserize Json object in Java object inside the Camel Route.

    That's what the object looks like.

      [
      "test",
      {
        "name": "1",
        "key": "4b588b18"
      }
    ]
    

    I want to deserize him into this object.

    public class SQSLargePay {
        private String name;
        private String value;
    
    public String getName() {
        return name;
    }
    
    public void setName(String Name) {
        this.name = name;
    }
    

    }

    I tried a lot of methods. Of the last one, this is a ridiculous attempt.

    String json = new Gson().toJson(exchange.getIn().getBody());
    SQSLargePay sqs = new Gson().fromJson(json, SQSLargePay.class);
    System.out.println(sqs.getName());

    And I get something like that.

    Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $

    The problem is, exchange.getIn().getBody() - It's ArrayList, so I have no idea how to tie it all up. I just need to get key/value to carry out the next action.

    Actually, the question is: How do you get a Camel castle for Json?



  • I think I should write my processor. To do this, we need to create an interface class. https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Processor.html ♪ It requires only one method of public void process(Exchange)


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2