Add JsonToPdxConverter interface specifying a contract to convert JSON to PDX.

The JSON may be expressed as a byte[] or a String.

Resolves gh-67.
This commit is contained in:
John Blum
2020-05-04 19:40:04 -07:00
parent 98c976fe6c
commit 8cb59be29c
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.data.json.converter;
import org.apache.geode.pdx.PdxInstance;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
/**
* A Spring {@link Converter} interface extension defining a contract to convert
* from a {@literal JSON} {@link String} to a {@link PdxInstance}.
*
* @author John Blum
* @see java.lang.FunctionalInterface
* @see org.apache.geode.pdx.PdxInstance
* @see org.springframework.core.convert.converter.Converter
* @since 1.3.0
*/
@FunctionalInterface
public interface JsonToPdxConverter extends Converter<String, PdxInstance> {
/**
* Converts the array of {@link Byte#TYPE bytes} containing {@literal JSON} into a {@link PdxInstance}.
*
* @param json array of {@link Byte#TYPE bytes} containing {@literal JSON}
* to convert into a {@link PdxInstance}; must not be {@literal null}.
* @return a {@link PdxInstance} converted from the array of {@link Byte#TYPE bytes} containing {@literal JSON}.
* @see #convert(Object)
*/
default @NonNull PdxInstance convert(@NonNull byte[] json) {
return convert(new String(json));
}
}