Class MoreStructs
Struct
messages.
The struct(name, value)
helpers can be used to create Struct
conveniently,
for example: struct("age", 10)
.
To build Struct
with more than one fields, use StructBuilder
; or use
toStruct()
to collect from a BiStream
.
If you have complex nested data structures such as Multimap<String, Optional<Integer>>
,
consider to use Structor
, which translates POJO to Struct for common primitive types and
collection types.
- Since:
- 5.8
-
Method Summary
Modifier and TypeMethodDescriptionasMap
(com.google.protobuf.Struct struct) Returns aMap<String, Object>
view overstruct
.static Collector
<com.google.protobuf.Struct, ?, com.google.protobuf.Struct> Returns aCollector
that flattens all fields from the inputStruct
s and collects them into the finalStruct
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static com.google.protobuf.Struct
Returns a Struct withname
andvalue
.static BiCollector
<CharSequence, com.google.protobuf.Value, com.google.protobuf.Struct> toStruct()
Returns aBiCollector
that collects the input key-value pairs intoStruct
.static <T> Collector
<T, ?, com.google.protobuf.Struct> toStruct
(Function<? super T, ? extends CharSequence> keyFunction, Function<? super T, com.google.protobuf.Value> valueFunction) Returns aCollector
that collects input key-value pairs intoStruct
.
-
Method Details
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
is null
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
is null
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
orvalue
is null
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
orvalue
is null
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
orvalue
is null
-
struct
Returns a Struct withname
andvalue
.- Throws:
NullPointerException
- ifname
orvalue
is null
-
toStruct
public static <T> Collector<T,?, toStructcom.google.protobuf.Struct> (Function<? super T, ? extends CharSequence> keyFunction, Function<? super T, com.google.protobuf.Value> valueFunction) Returns aCollector
that collects input key-value pairs intoStruct
.Duplicate keys (according to
CharSequence.toString()
) are not allowed. -
toStruct
public static BiCollector<CharSequence,com.google.protobuf.Value, toStruct()com.google.protobuf.Struct> Returns aBiCollector
that collects the input key-value pairs intoStruct
.Duplicate keys (according to
CharSequence.toString()
) are not allowed. -
flatteningToStruct
public static Collector<com.google.protobuf.Struct,?, flatteningToStruct()com.google.protobuf.Struct> Returns aCollector
that flattens all fields from the inputStruct
s and collects them into the finalStruct
.Duplicate field keys are not allowed.
-
asMap
Returns aMap<String, Object>
view overstruct
.Value
wrappers are unwrapped usingMoreValues.fromValue(com.google.protobuf.ValueOrBuilder)
, such thatValues.of(1)
is unwrapped to1L
,ListValue
is unwrapped asList<Object>
, andNullValue
is unwrapped asnull
, etc.Field encounter order is preserved in the result
Map
.- Since:
- 5.9
-