MultipartBody { public <T> Optional<T> getValueAsInstanceOptional( String key, Class<T> clazz) throws IOException { String valueAsString = getValueAsString(key); if (valueAsString == null) { return Optional.empty(); } return Optional.ofNullable(_parseValue(valueAsString, clazz)); } private  MultipartBody(
		Map<String, BinaryFile> binaryFiles,
		ObjectMapperProvider objectMapperProvider, Map<String, String> values); static MultipartBody of(
		Map<String, BinaryFile> binaryFiles,
		ObjectMapperProvider objectMapperProvider, Map<String, String> values); BinaryFile getBinaryFile(String key); byte[] getBinaryFileAsBytes(String key); T getValueAsInstance(String key, Class<T> clazz); Optional<T> getValueAsInstanceOptional(
			String key, Class<T> clazz); String getValueAsString(String key); Map<String, String> getValues();  }
@Test public void testGetValueAsInstanceOptional() throws IOException { MultipartBody multipartBody = MultipartBody.of( Collections.emptyMap(), __ -> _objectMapper, Collections.singletonMap( "key", JSONUtil.put( "list", Arrays.asList(1, 2, 3) ).put( "number", 42 ).put( "string", "Hello" ).toString())); Optional<TestClass> testClassOptional = multipartBody.getValueAsInstanceOptional("key", TestClass.class); assertThat(testClassOptional.isPresent(), is(true)); TestClass testClass = testClassOptional.get(); assertThat(testClass.list, contains(1, 2, 3)); assertThat(testClass.number, is(42L)); assertThat(testClass.string, is("Hello")); assertThat(testClass.testClass, is(nullValue())); testClassOptional = multipartBody.getValueAsInstanceOptional( "null", TestClass.class); assertThat(testClassOptional.isPresent(), is(false)); multipartBody = MultipartBody.of( Collections.emptyMap(), __ -> _objectMapper, Collections.singletonMap( "key", JSONUtil.put( "number", 42 ).put( "string", "Hello" ).put( "wrongKey", Arrays.asList(1, 2, 3) ).toString())); try { multipartBody.getValueAsInstance("key", TestClass.class); throw new AssertionError(); } catch (Exception exception) { assertThat( exception, is(instanceOf(UnrecognizedPropertyException.class))); } }