ValueProviders { @Deprecated public static String updateSerializedOptions( String serializedOptions, Map<String, String> runtimeValues) { ObjectNode root, options; try { root = PipelineOptionsFactory.MAPPER.readValue(serializedOptions, ObjectNode.class); options = (ObjectNode) root.get("options"); checkNotNull(options, "Unable to locate 'options' in %s", serializedOptions); } catch (IOException e) { throw new RuntimeException(String.format("Unable to parse %s", serializedOptions), e); } for (Map.Entry<String, String> entry : runtimeValues.entrySet()) { options.put(entry.getKey(), entry.getValue()); } try { return PipelineOptionsFactory.MAPPER.writeValueAsString(root); } catch (IOException e) { throw new RuntimeException("Unable to parse re-serialize options", e); } } private  ValueProviders(); @Deprecated static String updateSerializedOptions(
      String serializedOptions, Map<String, String> runtimeValues);  }
@Test public void testUpdateSerialize() throws Exception { TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class); String serializedOptions = MAPPER.writeValueAsString(submitOptions); String updatedOptions = ValueProviders.updateSerializedOptions(serializedOptions, ImmutableMap.of("string", "bar")); TestOptions runtime = MAPPER.readValue(updatedOptions, PipelineOptions.class).as(TestOptions.class); assertEquals("bar", runtime.getString()); }
@Test public void testUpdateSerializeExistingValue() throws Exception { TestOptions submitOptions = PipelineOptionsFactory.fromArgs("--string=baz", "--otherString=quux").as(TestOptions.class); String serializedOptions = MAPPER.writeValueAsString(submitOptions); String updatedOptions = ValueProviders.updateSerializedOptions(serializedOptions, ImmutableMap.of("string", "bar")); TestOptions runtime = MAPPER.readValue(updatedOptions, PipelineOptions.class).as(TestOptions.class); assertEquals("bar", runtime.getString()); assertEquals("quux", runtime.getOtherString()); }
@Test public void testUpdateSerializeEmptyUpdate() throws Exception { TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class); String serializedOptions = MAPPER.writeValueAsString(submitOptions); String updatedOptions = ValueProviders.updateSerializedOptions(serializedOptions, ImmutableMap.of()); TestOptions runtime = MAPPER.readValue(updatedOptions, PipelineOptions.class).as(TestOptions.class); assertNull(runtime.getString()); }