Class JsonValueFormatter

java.lang.Object
org.apache.juneau.commons.svl.JsonValueFormatter
All Implemented Interfaces:
Function<Object,String>

public class JsonValueFormatter extends Object implements Function<Object,String>
Default formatter that turns the typed result of a #{...} expression into text.

null becomes the empty string; CharSequence values are emitted as-is (bare, unquoted); numbers and booleans use toString (integral doubles drop the .0); a Structure uses its plain-text toString(); collections, maps and arrays are written as JSON (keys quoted, strings quoted only inside a container, null as null). Any other object inside a container is written as its quoted String.valueOf (there is no bean introspection here).

Nesting is capped at DEFAULT_MAX_DEPTH, each container at the configured element limit, and the whole call at MAX_NODES written values (so a shared acyclic DAG cannot fan out exponentially). A container that contains itself (a true cycle on the current path) is reported as a cycle. Beyond any limit the output is truncated with a single "..." marker in lenient mode, or a VarResolverException is thrown in strict mode; nothing here can overflow the stack.

JSON has no tokens for NaN or the infinities; inside containers they are written as the quoted strings "NaN", "Infinity" and "-Infinity". A double or float that is integral is written without the decimal point, so -0.0 is written as 0. The characters U+007F, U+2028 and U+2029 and all control characters below U+0020 are escaped as \\uXXXX; lone surrogates are written as-is.

  • Field Details

  • Constructor Details

    • JsonValueFormatter

      Constructor using the default collection limit, lenient.
    • JsonValueFormatter

      public JsonValueFormatter(int maxSize, boolean strict)
      Constructor.
      Parameters:
      maxSize - Maximum elements written per container.
      strict - true to throw instead of truncating when a limit is exceeded.
  • Method Details