/** * Creates a new {@link Printer} that will also print default-valued fields if their * FieldDescriptors are found in the supplied set. Empty repeated fields and map fields will be * printed as well, if they match. The new Printer clones all other configurations from the * current {@link Printer}. Call includingDefaultValueFields() with no args to unconditionally * output all fields. */ public Printer includingDefaultValueFields(Set<FieldDescriptor> fieldsToAlwaysOutput) { Preconditions.checkArgument( null != fieldsToAlwaysOutput && !fieldsToAlwaysOutput.isEmpty(), "Non-empty Set must be supplied for includingDefaultValueFields."); checkUnsetIncludingDefaultValueFields(); return new Printer( registry, false, fieldsToAlwaysOutput, preservingProtoFieldNames, omittingInsignificantWhitespace, printingEnumsAsInts); }
/** * Creates a {@link Printer} with default configurations. */ public static Printer printer() { return new Printer( TypeRegistry.getEmptyTypeRegistry(), false, Collections.<FieldDescriptor>emptySet(), false, false, false); }
/** * Creates a new {@link Printer} that will also print fields set to their * defaults. Empty repeated fields and map fields will be printed as well. * The new Printer clones all other configurations from the current * {@link Printer}. */ public Printer includingDefaultValueFields() { checkUnsetIncludingDefaultValueFields(); return new Printer( registry, true, Collections.<FieldDescriptor>emptySet(), preservingProtoFieldNames, omittingInsignificantWhitespace, printingEnumsAsInts); }
/** * Create a new {@link Printer} that will omit all insignificant whitespace in the JSON output. * This new Printer clones all other configurations from the current Printer. Insignificant * whitespace is defined by the JSON spec as whitespace that appear between JSON structural * elements: * * <pre> * ws = *( * %x20 / ; Space * %x09 / ; Horizontal tab * %x0A / ; Line feed or New line * %x0D ) ; Carriage return * </pre> * * See <a href="https://tools.ietf.org/html/rfc7159">https://tools.ietf.org/html/rfc7159</a> * current {@link Printer}. */ public Printer omittingInsignificantWhitespace() { return new Printer( registry, alwaysOutputDefaultValueFields, includingDefaultValueFields, preservingProtoFieldNames, true, printingEnumsAsInts); }
/** * Creates a new {@link Printer} using the given registry. The new Printer * clones all other configurations from the current {@link Printer}. * * @throws IllegalArgumentException if a registry is already set. */ public Printer usingTypeRegistry(TypeRegistry registry) { if (this.registry != TypeRegistry.getEmptyTypeRegistry()) { throw new IllegalArgumentException("Only one registry is allowed."); } return new Printer( registry, alwaysOutputDefaultValueFields, includingDefaultValueFields, preservingProtoFieldNames, omittingInsignificantWhitespace, printingEnumsAsInts); }
/** * Creates a new {@link Printer} that will print enum field values as integers instead of as * string. * The new Printer clones all other configurations from the current * {@link Printer}. */ public Printer printingEnumsAsInts() { checkUnsetPrintingEnumsAsInts(); return new Printer( registry, alwaysOutputDefaultValueFields, Collections.<FieldDescriptor>emptySet(), preservingProtoFieldNames, omittingInsignificantWhitespace, true); }
/** * Creates a new {@link Printer} that is configured to use the original proto * field names as defined in the .proto file rather than converting them to * lowerCamelCase. The new Printer clones all other configurations from the * current {@link Printer}. */ public Printer preservingProtoFieldNames() { return new Printer( registry, alwaysOutputDefaultValueFields, includingDefaultValueFields, true, omittingInsignificantWhitespace, printingEnumsAsInts); }