Class ReadOnlyStringMapResolver

  • All Implemented Interfaces:
    EventResolver, TemplateResolver<LogEvent>
    Direct Known Subclasses:
    MapResolver, ThreadContextDataResolver

    class ReadOnlyStringMapResolver
    extends java.lang.Object
    implements EventResolver
    ReadOnlyStringMap resolver.

    Configuration

     config        = singleAccess | multiAccess
    
     singleAccess  = key , [ stringified ]
     key           = "key" -> string
     stringified   = "stringified" -> boolean
    
     multiAccess   = [ pattern ] , [ replacement ] , [ flatten ] , [ stringified ]
     pattern       = "pattern" -> string
     replacement   = "replacement" -> string
     flatten       = "flatten" -> ( boolean | flattenConfig )
     flattenConfig = [ flattenPrefix ]
     flattenPrefix = "prefix" -> string
     
    Note that singleAccess resolves a single field, whilst multiAccess resolves a multitude of fields. If flatten is provided, multiAccess merges the fields with the parent, otherwise creates a new JSON object containing the values.

    Enabling stringified flag converts each value to its string representation.

    Regex provided in the pattern is used to match against the keys. If provided, replacement will be used to replace the matched keys. These two are effectively equivalent to Pattern.compile(pattern).matcher(key).matches() and Pattern.compile(pattern).matcher(key).replaceAll(replacement) calls.

    Garbage Footprint

    stringified allocates a new String for values that are not of type String.

    pattern and replacement incur pattern matcher allocation costs.

    Writing certain non-primitive values (e.g., BigDecimal, Set, etc.) to JSON generates garbage, though most (e.g., int, long, String, List, boolean[], etc.) don't.

    Examples

    "$resolver" is left out in the following examples, since it is to be defined by the actual resolver, e.g., MapResolver, ThreadContextDataResolver.

    Resolve the value of the field keyed with user:role:

     {
       "$resolver": "…",
       "key": "user:role"
     }
     
    Resolve the string representation of the user:rank field value:
     {
       "$resolver": "…",
       "key": "user:rank",
       "stringified": true
     }
     
    Resolve all fields into an object:
     {
       "$resolver": "…"
     }
     
    Resolve all fields into an object such that values are converted to string:
     {
       "$resolver": "…",
       "stringified": true
     }
     
    Resolve all fields whose keys match with the user:(role|rank) regex into an object:
     {
       "$resolver": "…",
       "pattern": "user:(role|rank)"
     }
     
    Resolve all fields whose keys match with the user:(role|rank) regex into an object after removing the user: prefix in the key:
     {
       "$resolver": "…",
       "pattern": "user:(role|rank)",
       "replacement": "$1"
     }
     
    Merge all fields whose keys are matching with the user:(role|rank) regex into the parent:
     {
       "$resolver": "…",
       "flatten": true,
       "pattern": "user:(role|rank)"
     }
     
    After converting the corresponding field values to string, merge all fields to parent such that keys are prefixed with _:
     {
       "$resolver": "…",
       "stringified": true,
       "flatten": {
         "prefix": "_"
       }
     }
     
    See Also:
    MapResolver, ThreadContextDataResolver