@Override protected String doForward(String s) { return sourceFormat.to(targetFormat, s); }
@Override protected String doBackward(String s) { return targetFormat.to(sourceFormat, s); }
/** * 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. */ public static String toJsonString(FieldMask fieldMask) { List<String> paths = new ArrayList<String>(fieldMask.getPathsCount()); for (String path : fieldMask.getPathsList()) { if (path.isEmpty()) { continue; } paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path)); } return Joiner.on(FIELD_PATH_SEPARATOR).join(paths); }
/** * Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and * converting from camel case to snake case. */ public static FieldMask fromJsonString(String value) { Iterable<String> paths = Splitter.on(FIELD_PATH_SEPARATOR).split(value); FieldMask.Builder builder = FieldMask.newBuilder(); for (String path : paths) { if (path.isEmpty()) { continue; } builder.addPaths(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, path)); } return builder.build(); }