Class V2JsonBody
java.lang.Object
org.codelibs.fess.api.v2.handlers.V2JsonBody
Reads a JSON-encoded request body into a Map and returns it.
Rejects payloads larger than maxBytes, content types other than
application/json, and malformed JSON. The empty body is treated as
an empty map so callers do not need to null-check before lookups.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when the request body is not parseable as JSON.static classThrown when the request body exceeds the configured maximum byte size.static classThrown when the requestContent-Typeis notapplication/json. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
V2JsonBody
public V2JsonBody()Creates the v2 JSON body reader. Registered as the DI componentv2JsonBodyand obtained viaComponentUtil.getV2JsonBody().
-
-
Method Details
-
read
public Map<String,Object> read(jakarta.servlet.http.HttpServletRequest req, int maxBytes) throws IOException Reads a JSON-encoded request body into aMap<String, Object>.Enforces the following rules before parsing:
- Content-Type required: a
nullor absent Content-Type header is rejected withV2JsonBody.UnsupportedMediaTypeException. - application/json only: any Content-Type whose base media type is
not
application/jsonis rejected withV2JsonBody.UnsupportedMediaTypeException. - UTF-8 charset only: if the Content-Type includes an explicit
charsetparameter, it must beutf-8(case-insensitive); any other charset is rejected withV2JsonBody.UnsupportedMediaTypeException. - Size limit: bodies longer than
maxBytesare rejected withV2JsonBody.PayloadTooLargeException. - BOM stripping: a leading UTF-8 BOM (0xEF 0xBB 0xBF) is silently removed before parsing so that editor-generated JSON files are accepted.
- Parameters:
req- the incoming HTTP requestmaxBytes- maximum accepted body length in bytes- Returns:
- parsed body as a map; an empty body returns an empty (immutable) map
- Throws:
V2JsonBody.UnsupportedMediaTypeException- if the Content-Type is absent, not application/json, or specifies a non-UTF-8 charsetV2JsonBody.PayloadTooLargeException- if the body exceedsmaxBytesV2JsonBody.MalformedJsonException- if the body is not valid JSONIOException- if reading the request stream fails
- Content-Type required: a
-