Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:04:37+00:00 2026-06-04T10:04:37+00:00

I’ve spent quite a while trying to figure this out. I am working on

  • 0

I’ve spent quite a while trying to figure this out. I am working on writing a service which receives a user name and password. It then uses a processor to generate an authentication token which is returned in the Out part of the message. I want to accept JSON formatted parameters, and am trying to get type conversion to work correctly. I’ve reduced the problem to a self contained unit test which is below:

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JsonDataFormat;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import com.thoughtworks.xstream.annotations.XStreamAlias;


public class BasicJsonMarshallingTest extends CamelTestSupport {

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    final Processor simpleProcessor = new Processor() {
        @Override public void process(Exchange exchange) throws Exception {
            SimpleBean bean = exchange.getIn().getBody(SimpleBean.class);
            if(bean == null){
                return;
            }
            exchange.getOut().setBody("a=" + bean.getA() + " b=" + bean.getB());
        }
    };

    return new RouteBuilder() {
        @Override public void configure() throws Exception {
            JsonDataFormat jsonFormat = new JsonDataFormat(JsonLibrary.XStream);
            jsonFormat.setUnmarshalType(SimpleBean.class);
            from("direct:service").unmarshal(jsonFormat).process(simpleProcessor);
        }
    };
}

@Test
public void testSuccessfulAuthentication(){
    Exchange lAuthRequest = createExchangeWithBody("{\"simple\":{\"a\":\"v1\",\"b\":\"v2\"}}");
    template.send("direct:service", lAuthRequest);
    assertEquals("a=v1 b=v2", lAuthRequest.getOut().getBody());
}

@XStreamAlias("simple")
public static final class SimpleBean {

    private String a;
    private String b;

    public void setA(String a) {
        this.a = a;
    }
    public String getA() {
        return a;
    }
    public void setB(String b) {
        this.b = b;
    }
    public String getB() {
        return b;
    }

}

}

When I run this test, I get this exception in the console:

com.thoughtworks.xstream.mapper.CannotResolveClassException: simple
    at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)[xstream-1.4.1.jar:]
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)[xstream-1.4.1.jar:]
    <snip>

Am I approaching this wrong somehow? Please Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:04:38+00:00Added an answer on June 4, 2026 at 10:04 am

    I found one way to make this work. I switched to Jackson as my JSON parser and it worked. To do this, all I had to do was change the RouteBuilder to this:

        return new RouteBuilder() {
            @Override public void configure() throws Exception {
                from("direct:service").unmarshal().json(JsonLibrary.Jackson, SimpleBean.class).process(simpleProcessor);
            }
        };
    

    I also had to change the format of the JSON being sent over the wire from this:

    {“simple”:{“a”:”v1″,”b”:”v2″}}

    to this (which I like more anyway):

    {“a”:”v1″, “b”:”v2″}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.