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.
Converts a FieldMask to its canonical form. In the canonical form of a
FieldMask, all field paths are sorted alphabetically and redundant field
paths are removed.
This method disregards proto structure. That is, iffirstMaskis "foo" andsecondMaskis "foo.bar", the response will always be "foo" without considering the internal
proto structure of message "foo".
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class FieldMaskUtil (3.19.4)\n\n public final class FieldMaskUtil\n\nUtility helper functions to work with [com.google.protobuf.FieldMask](/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask). \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e FieldMaskUtil \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### \\\u003cP\\\u003etrim(FieldMask mask, P source)\n\n public static P \u003cP\u003etrim(FieldMask mask, P source)\n\nReturns the result of keeping only the masked fields of the given proto.\n\n### fromFieldNumbers(Class\\\u003c? extends Message\\\u003e type, int\\[\\] fieldNumbers)\n\n public static FieldMask fromFieldNumbers(Class\u003c? extends Message\u003e type, int[] fieldNumbers)\n\nConstructs a FieldMask from the passed field numbers.\n\n### fromFieldNumbers(Class\\\u003c? extends Message\\\u003e type, Iterable\\\u003cInteger\\\u003e fieldNumbers)\n\n public static FieldMask fromFieldNumbers(Class\u003c? extends Message\u003e type, Iterable\u003cInteger\u003e fieldNumbers)\n\nConstructs a FieldMask from the passed field numbers.\n\n### fromJsonString(String value)\n\n public static FieldMask fromJsonString(String value)\n\nConverts a field mask from a Proto3 JSON string, that is splitting the paths along commas and\nconverting from camel case to snake case.\n\n### fromString(Class\\\u003c? extends Message\\\u003e type, String value)\n\n public static FieldMask fromString(Class\u003c? extends Message\u003e type, String value)\n\nParses from a string to a FieldMask and validates all field paths.\n\n### fromString(String value)\n\n public static FieldMask fromString(String value)\n\nParses from a string to a FieldMask.\n\n### fromStringList(Descriptors.Descriptor descriptor, Iterable\\\u003cString\\\u003e paths)\n\n public static FieldMask fromStringList(Descriptors.Descriptor descriptor, Iterable\u003cString\u003e paths)\n\nConstructs a FieldMask for a list of field paths in a certain type.\n\n### fromStringList(Class\\\u003c? extends Message\\\u003e type, Iterable\\\u003cString\\\u003e paths)\n\n public static FieldMask fromStringList(Class\u003c? extends Message\u003e type, Iterable\u003cString\u003e paths)\n\nConstructs a FieldMask for a list of field paths in a certain type.\n\n### fromStringList(Iterable\\\u003cString\\\u003e paths)\n\n public static FieldMask fromStringList(Iterable\u003cString\u003e paths)\n\nConstructs a FieldMask for a list of field paths in a certain type. Does not validate the given\npaths.\n\n### intersection(FieldMask mask1, FieldMask mask2)\n\n public static FieldMask intersection(FieldMask mask1, FieldMask mask2)\n\nCalculates the intersection of two FieldMasks.\n\n### isValid(Descriptors.Descriptor descriptor, FieldMask fieldMask)\n\n public static boolean isValid(Descriptors.Descriptor descriptor, FieldMask fieldMask)\n\nChecks whether paths in a given fields mask are valid.\n\n### isValid(Descriptors.Descriptor descriptor, String path)\n\n public static boolean isValid(Descriptors.Descriptor descriptor, String path)\n\nChecks whether paths in a given fields mask are valid.\n\n### isValid(Class\\\u003c? extends Message\\\u003e type, FieldMask fieldMask)\n\n public static boolean isValid(Class\u003c? extends Message\u003e type, FieldMask fieldMask)\n\nChecks whether paths in a given fields mask are valid.\n\n### isValid(Class\\\u003c? extends Message\\\u003e type, String path)\n\n public static boolean isValid(Class\u003c? extends Message\u003e type, String path)\n\nChecks whether a given field path is valid.\n\n### merge(FieldMask mask, Message source, Message.Builder destination)\n\n public static void merge(FieldMask mask, Message source, Message.Builder destination)\n\nMerges fields specified by a FieldMask from one message to another.\n\n### merge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)\n\n public static void merge(FieldMask mask, Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options)\n\nMerges fields specified by a FieldMask from one message to another with the specified merge\noptions. The destination will remain unchanged if an empty FieldMask is provided.\n\n### normalize(FieldMask mask)\n\n public static FieldMask normalize(FieldMask mask)\n\nConverts a FieldMask to its canonical form. In the canonical form of a\nFieldMask, all field paths are sorted alphabetically and redundant field\npaths are removed.\n\n### subtract(FieldMask firstMask, FieldMask secondMask, FieldMask\\[\\] otherMasks)\n\n public static FieldMask subtract(FieldMask firstMask, FieldMask secondMask, FieldMask[] otherMasks)\n\nSubtracts `secondMask` and `otherMasks` from `firstMask`.\n\nThis method disregards proto structure. That is, if `firstMask` is \"foo\" and `\nsecondMask` is \"foo.bar\", the response will always be \"foo\" without considering the internal\nproto structure of message \"foo\".\n\n### toJsonString(FieldMask fieldMask)\n\n public static String toJsonString(FieldMask fieldMask)\n\nConverts a field mask to a Proto3 JSON string, that is converting from snake case to camel\ncase and joining all paths into one string with commas.\n\n### toString(FieldMask fieldMask)\n\n public static String toString(FieldMask fieldMask)\n\nConverts a FieldMask to a string.\n\n### union(FieldMask firstMask, FieldMask secondMask, FieldMask\\[\\] otherMasks)\n\n public static FieldMask union(FieldMask firstMask, FieldMask secondMask, FieldMask[] otherMasks)\n\nCreates a union of two or more FieldMasks."]]