1

I want to hide id_jadwal in the display JSON. but now id_jadwal keep display on my JSON I want to hide id_jadwal in the display JSON. I am using MongoDB and java jx-rs for my framework and Jackson

[
    {
        "name": "Style",
        "startTimestamp": 1507611720,
        "endTimestamp": null,
        "place": "gh",
        "description": "gh",
        "status": "DONE",
        "creator": {
            "name": "Pulan",
            "email": "[email protected]",
            "photo": "https://lh6.googleusercontent.com/-Q5Tx0bdvkAU/AAAAAAAAAAI/AAAAAAAAEyU/83rb_x1tyXA/photo.jpg"
        },
        "invitedUsers": [
            {
                "name": "Petra",
                "email": "[email protected]",
                "photo": "",
                "present": false,
                "nearby": false
            }
        ],
        "id_jadwal": null,
        "_id": "59db02e8212cba197b7e9d2c"
    }

}]

My Code:

BasicDBObject query = new BasicDBObject();
query.put("creator.email", email);
query.put("status", status.toString());
MongoCursor<Document> cursor = collection.find(query).iterator();
ObjectMapper objectMapper = new ObjectMapper();

while (cursor.hasNext()) {
    String jsonUser = cursor.next().toJson();

    Event event = objectMapper.readValue(jsonUser, Event.class);
    //objectMapper.setVisibility(event.getId_jadwal(), Visibility.NONE);

    events.add(event);
    events.remove("id_jadwal");

}

1 Answer 1

1

you have to explicitely exclude your field at request level, using Projection :

MongoCursor<Document> cursor = collection.find(query).projection(Projections.exclude("id_jadwal").iterator();
Sign up to request clarification or add additional context in comments.

2 Comments

keep display id_jadwal but become to null value
probably because your Event class has id_jadwal property, but your ObjectMapper can not get value from query result (as we removed it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.