0

I have this rest result in url:"http:....:

{ took: 48,
    timed_out: false,
       _shards: {
    total: 5,
    successful: 5,
    failed: 0
    },
    hits: {
    total: 111,
    max_score: 1,
    hits: [
    {
    _index: "errors",
    _type: "error",
    _id: "AV0Sd2dn-sq8yPidLBWo",
    _score: 1,
    _source: {
    date: "16:54:46,215",
    path: "c:/logstash.log",
    @timestamp: "2017-07-05T11:16:40.560Z",
    level: "ERROR",
    @version: "1",
    host: "User",
    message:
    "16:54:46,215 ERROR [stderr] (ServerService Thread Pool -- 42) ch.qos.logback.core.joran.spi.JoranException: Problem parsing XML document. See previously reported errors."

I want to retrieve just this result and convert it to a list of objects that contains juste: date,level and message.

hits: [
        {
        _index: "errors",
        _type: "error",
        _id: "AV0Sd2dn-sq8yPidLBWo",
        _score: 1,
        _source: {
        date: "16:54:46,215",
        path: "c:/logstash.log",
        @timestamp: "2017-07-05T11:16:40.560Z",
        level: "ERROR",
        @version: "1",
        host: "User",
        message: [
        "16:54:46,215 ERROR [stderr] (ServerService Thread Pool -- 42) ch.qos.logback.core.joran.spi.JoranException: Problem parsing XML document. See previously reported errors."
]}}

----Edit--- this is my class:

public class Error {
 private String date;
 private String level;
 private String message;
}

So i want create an object Error from the reslt of json.Exactly from this

_source: {
    date: "16:54:46,215",
    path: "c:/logstash.log",
    @timestamp: "2017-07-05T11:16:40.560Z",
    level: "ERROR",
    @version: "1",
    host: "User",
    message:
    "16:54:46,215 ERROR [stderr] (ServerService Thread Pool -- 42) ch.qos.logback.core.joran.spi.JoranException: Problem parsing XML document. See previously reported errors."

Any help is greatly appreciate.

4
  • Mind as well share us your code? Commented Jul 7, 2017 at 11:36
  • possible duplicate of (stackoverflow.com/questions/12460378/…) Commented Jul 7, 2017 at 11:37
  • This title really should read "how do I build a new object based on an existing object". Commented Jul 7, 2017 at 11:37
  • I think it's helps for convert json to object Example Commented Jul 7, 2017 at 11:42

0

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.