Git Product home page Git Product logo

Comments (3)

raulk avatar raulk commented on June 24, 2024

Hi @rsvalerio!

BasicDBObject implements Map<String, Object>: http://api.mongodb.org/java/current/com/mongodb/BasicDBObject.html.

So this should already be possible.

What exception are you getting?

Regards,
Raรบl.

from camel-mongodb.

rsvalerio avatar rsvalerio commented on June 24, 2024

Hi @raulk .

Well, my problem is:

Route:

        from("direct:get.beers")
        .to("mongodb:local?database=poc&collection=beers&operation=findAll")
        .split().body()
            .convertBodyTo(String.class)
            .unmarshal().xmljson()
            .log(LoggingLevel.DEBUG, "### ${body}")
            .end();

Throws:

nu.xom.IllegalNameException: NCNames cannot start with the character 24

Because:

{
  "_id": {
    "$oid": "538b8b63d69eb687a19caef7"
  },
  "type": "strong"
}

But even toMap() have an invalid json response:

    public void toMap (
            Exchange exchange,
            @Body Map<String, Object> bodyImplementsMap ) {

        Map<String, Object> bodyToMap = ((BasicDBObject)bodyImplementsMap).toMap();

        exchange.getIn().setHeader("bodyImplementsMap", bodyImplementsMap);
        exchange.getIn().setHeader("bodyToMap", bodyToMap);
    }

bodyImplementsMap (valid json, invalid xml because $) :

{
  "_id": {
    "$oid": "538b8b63d69eb687a19caef7"
  },
  "type": "strong"
}

bodyToMap (invalid json, miss "", valid xml ) :

{
  _id = 538b8b63d69eb687a19caef7, 
  type = strong
}

from camel-mongodb.

rsvalerio avatar rsvalerio commented on June 24, 2024

By now, converting response body from mongodb to Map as follows:

    public void toMap ( Exchange exchange, @Body BasicDBObject body) {
        ObjectId id = body.getObjectId("_id");
        body.put("_id", id.toString());
        exchange.getIn().setBody(body.clone());
    }

from camel-mongodb.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.