Class FieldMaskUtil
java.lang.Object
com.google.protobuf.util.FieldMaskUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOptions to customize merging behavior.static final classOptions to customize trimming behavior. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldMaskfromFieldNumbers(Class<? extends Message> type, int... fieldNumbers) Constructs a FieldMask from the passed field numbers.static FieldMaskfromFieldNumbers(Class<? extends Message> type, Iterable<Integer> fieldNumbers) Constructs a FieldMask from the passed field numbers.static FieldMaskfromJsonString(String value) Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and converting from camel case to snake case.static FieldMaskfromString(Class<? extends Message> type, String value) Parses from a string to a FieldMask and validates all field paths.static FieldMaskfromString(String value) Parses from a string to a FieldMask.static FieldMaskfromStringList(Descriptors.Descriptor descriptor, Iterable<String> paths) Constructs a FieldMask for a list of field paths in a certain type.static FieldMaskfromStringList(Class<? extends Message> type, Iterable<String> paths) Constructs a FieldMask for a list of field paths in a certain type.static FieldMaskfromStringList(Iterable<String> paths) Constructs a FieldMask for a list of field paths in a certain type.private static FieldMaskfromStringList(Optional<Descriptors.Descriptor> descriptor, Iterable<String> paths) static FieldMaskintersection(FieldMask mask1, FieldMask mask2) Calculates the intersection of two FieldMasks.static booleanisValid(Descriptors.Descriptor descriptor, FieldMask fieldMask) Checks whether paths in a given fields mask are valid.static booleanisValid(Descriptors.Descriptor descriptor, String path) Checks whether paths in a given fields mask are valid.static booleanChecks whether paths in a given fields mask are valid.static booleanChecks whether a given field path is valid.private static StringConverts a lowerCamelCase string to lower_underscore style.private static StringConverts a lower_underscore to lowerCamelCase style.static voidmerge(FieldMask mask, Message source, Message.Builder destination) Merges fields specified by a FieldMask from one message to another.static voidmerge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges fields specified by a FieldMask from one message to another with the specified merge options.static FieldMaskConverts a FieldMask to its canonical form.static FieldMaskSubtractssecondMaskandotherMasksfromfirstMask.static StringtoJsonString(FieldMask fieldMask) Converts a field mask to a Proto3 JSON string, that is converting from snake case to camel case and joining all paths into one string with commas.static StringConverts a FieldMask to a string.static <P extends Message>
PReturns the result of keeping only the masked fields of the given proto.static <P extends Message>
Ptrim(FieldMask mask, P source, FieldMaskUtil.TrimOptions options) Returns the result of keeping only the masked fields of the given proto with the specified trim options.static FieldMaskCreates a union of two or more FieldMasks.
-
Field Details
-
FIELD_PATH_SEPARATOR
- See Also:
-
FIELD_PATH_SEPARATOR_REGEX
- See Also:
-
FIELD_SEPARATOR_REGEX
- See Also:
-
-
Constructor Details
-
FieldMaskUtil
private FieldMaskUtil()
-
-
Method Details
-
toString
-
fromString
-
fromString
Parses from a string to a FieldMask and validates all field paths.- Throws:
IllegalArgumentException- if any of the field path is invalid.
-
fromStringList
-
fromStringList
Constructs a FieldMask for a list of field paths in a certain type.- Throws:
IllegalArgumentException- if any of the field path is not valid.
-
fromStringList
-
fromStringList
private static FieldMask fromStringList(Optional<Descriptors.Descriptor> descriptor, Iterable<String> paths) -
fromFieldNumbers
Constructs a FieldMask from the passed field numbers.- Throws:
IllegalArgumentException- if any of the fields are invalid for the message.
-
fromFieldNumbers
-
lowerUnderscoreToLowerCamel
-
lowerCamelToLowerUnderscore
-
toJsonString
-
fromJsonString
-
isValid
-
isValid
Checks whether paths in a given fields mask are valid. -
isValid
-
isValid
Checks whether paths in a given fields mask are valid. -
normalize
-
union
-
subtract
public static FieldMask subtract(FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks) SubtractssecondMaskandotherMasksfromfirstMask.This method disregards proto structure. That is, if
firstMaskis "foo" andsecondMaskis "foo.bar", the response will always be "foo" without considering the internal proto structure of message "foo". -
intersection
-
merge
public static void merge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) Merges fields specified by a FieldMask from one message to another with the specified merge options. The destination will remain unchanged if an empty FieldMask is provided. -
merge
Merges fields specified by a FieldMask from one message to another. -
trim
public static <P extends Message> P trim(FieldMask mask, P source, FieldMaskUtil.TrimOptions options) Returns the result of keeping only the masked fields of the given proto with the specified trim options.Note that the behavior with the default
FieldMaskUtil.TrimOptionsis for unset primitive fields indicated in the field mask to be explicitly set to their default values. Usenew TrimOptions().setRetainPrimitiveFieldUnsetState(true)to retain the unset state of primitive fields. -
trim
Returns the result of keeping only the masked fields of the given proto.This method is equivalent to
trim(FieldMask, Message, TrimOptions)with defaultFieldMaskUtil.TrimOptions.Note that unset primitive fields indicated in the field mask will be explicitly set to their default values.
-