1

I am working on a camel route for a REST service. My task is to add a POST in which I need to take a token out of the json that is sent. I am doing the following:

.unmarshal().json(JsonLibrary.Jackson, Token.class)

I added the "camel-jackson" dependency to my pom file and it works fine.

Problem: Now all the json coming is has the double quotation marks stripped off. So the following json:

{"name": "John Doe", "job": "farmer"}

Ends up as:

{name:John Doe,job:farmer}

For some of my code I need the double quotes. I have tried to do a bit of configuring my rest route with no luck. Any one have an idea of a fix?

Norman Skinner
  • 6,729
  • 1
  • 19
  • 22

1 Answers1

0

You mention in the comment that you have

restConfiguration()
    .component("jetty") 
    .scheme("https") 
    .bindingMode(RestBindingMode.auto) 
    .dataFormatProperty("prettyPrint", "true") 
    .port(8443);

You don't mention what your route is. However, if you're using bindingMode it will expect a type() on the get()/post() which will be used to unmarshal json into. It sounds like you only want to do this for the new POST you are adding, so why not have the binding on the post() rather than globally on the restConfiguration()?

e.g.

restConfiguration()
    .component("jetty") 
    .scheme("https") 
    .dataFormatProperty("prettyPrint", "true") 
    .port(8443);

rest("/words")
    .post("/new/post/url")
        .bindingMode(RestBindingMode.auto) 
        .type(YourPojo.class)
        ... 
    .get("existing/stuff")
        ... 
pcoates
  • 2,102
  • 1
  • 9
  • 20
  • The real focus is my REST route was taking in json with quotes. As soon as I added the "camel-jackson" dependency to the pom it instantly started stripping the quotes. Here is my "restConfiguration" .component("jetty") .scheme("https") .bindingMode(RestBindingMode.auto) .dataFormatProperty("prettyPrint", "true") .port(8443); – Norman Skinner Dec 28 '18 at 21:38
  • If you show the full route, the input and how you know it's been stripped you're more likely to get a useful answer. And post the restConfiguration into your question too. – pcoates Dec 28 '18 at 21:40
  • Camel is stripping the double quotes out of my JSON string so parsing fails. I am trying to do a schema validation so I need the raw string. Using type(YourPojo.class) provides no useful information if there is a problem the incoming JSON – Gerry Jan 17 '22 at 19:23