njk2015
njk2015

Reputation: 543

Spring boot - accessing raw json data

I am following a spring boot tutorial here:

Spring boot tutorial for consuming a rest service

The tutorial works fine, but is there a way I can print the raw JSON before it is unmarshalled (via the jackson JSON processing library) for logging purposes?

Upvotes: 1

Views: 1394

Answers (1)

Marc Tarin
Marc Tarin

Reputation: 3169

The quickest way to do this is to set the log level to DEBUG for the HTTP input buffer : simply add logging.level.org.apache.coyote.http11.Http11InputBuffer = DEBUG to your src/main/resources/application.properties file. You should then see something similar to the following lines in your log messages:

2017-02-28 17:35:03.554 DEBUG 856 --- [nio-8443-exec-5] o.a.coyote.http11.Http11InputBuffer      : Received [POST /tasks HTTP/1.1
Host: localhost:8443
Authorization: Basic ****************
User-Agent: curl/7.51.0
Accept: */*
content-type:application/json
Content-Length: 17

{ "foo" : "bar" }]

Also check this SO post where I offered several options regarding tinkering with the raw JSON content with home made controller methods.

Upvotes: 3

Related Questions