Java Code Examples for com.google.api.client.json.JsonGenerator#writeFieldName()
The following examples show how to use
com.google.api.client.json.JsonGenerator#writeFieldName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnauthorizedServlet.java From HotswapAgentExamples with GNU General Public License v2.0 | 6 votes |
protected void unauthorized(HttpServletRequest req, HttpServletResponse resp) throws IOException { String userAgent = req.getHeader("User-Agent"); resp.setHeader("Content-Type", "text/javascript"); resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); JsonGenerator generator = jsonFactory.createJsonGenerator(resp.getWriter()); generator.writeStartObject(); generator.writeFieldName("error"); generator.writeString("Login required."); generator.writeFieldName("q"); generator.writeString(req.getQueryString()); generator.writeFieldName("agent"); generator.writeString(userAgent); generator.writeEndObject(); generator.flush(); }
Example 2
Source File: JsonHttpContent.java From google-http-java-client with Apache License 2.0 | 5 votes |
public void writeTo(OutputStream out) throws IOException { JsonGenerator generator = jsonFactory.createJsonGenerator(out, getCharset()); if (wrapperKey != null) { generator.writeStartObject(); generator.writeFieldName(wrapperKey); } generator.serialize(data); if (wrapperKey != null) { generator.writeEndObject(); } generator.flush(); }