Search code examples
javajsonplayframeworkplayframework-2.2

How can I only return some fields in the JSON object?


I currently have a function that returns a JSON version of an object:

public class Debate extends Controller
{
    public static Result viewArgument(Long id)
    {
        ...
        return ok(Json.toJson(Argument.get(id)));
    }
}

This Argument object has some confidential information that should not be exposed to the client, however. How can I select only the fields id and summary to be returned in the resulting JSON object?


Solution

  • There is a simpler answer, just add @JsonIgnore to the other fields.