println of itemResponse's body works, but PrintWriters.println prints id field instead

11 views
Skip to first unread message

klostar7777

unread,
Apr 6, 2016, 4:11:27 AM4/6/16
to Guardian Open Platform API Forum


Hi,


If I run a single item query and process the response either with a map or foreach to 'println' the body of the article it works as I expect it, ie prints body of article to stdout as I want it to. But if I instead write to a file (using PrintWriter) it prints the “id” field of struct ContentFields:


    val output = new PrintWriter(new File(filename))

    val itemBodyQuery = ItemQuery(result.id)

    .showFields("body")


    client.getResponse(itemBodyQuery) map { response =>

    output.println(response.content.get.fields.get.body.get)        // This prints “id”

    // println(response.content.get.fields.get.body.get)                // This prints “body”

    }


In the file output version it prints for example the following to the file:

society/live/2016/apr/06/junior-doctors-strike-for-fourth-time-over-new-contract-live-updates


instead of the body text.


Please can you help me understand why this is happening ?  The executions are identical except for println/output.println statement switch,


Thanks  


Karen

Reply all
Reply to author
Forward
0 new messages