public final class PropertiesToJsonConverter extends Object
| Modifier and Type | Method and Description |
|---|---|
String |
convertFromValuesAsObjectMap(Map<String,Object> properties)
It generates Json given Map<String,Object> instance.
|
String |
convertFromValuesAsObjectMap(Map<String,Object> properties,
boolean tryConvertStringValuesToOtherObjects)
It generates Json from given Map<String,Object> instance.
|
String |
convertFromValuesAsObjectMap(Map<String,Object> properties,
String... includeDomainKeys)
It generates Json given Map<String,Object> instance and will converts only included keys or parts of property keys provided by second parameter.
|
String |
convertPropertiesFromFileToJson(File file)
It generates Json from properties file stored in provided File.
|
String |
convertPropertiesFromFileToJson(File file,
String... includeDomainKeys)
It generates Json from properties file stored in provided File and will converts only included keys or parts of property keys provided by second
parameter.
|
String |
convertPropertiesFromFileToJson(String pathToFile)
It generates Json from properties file stored in provided path as string.
|
String |
convertPropertiesFromFileToJson(String pathToFile,
String... includeDomainKeys)
It generates Json from properties file stored in provided path as string and will converts only included keys or parts of property keys provided by
second parameter.
|
String |
convertToJson(InputStream inputStream)
It generates Json from properties stored in provided InputStream.
|
String |
convertToJson(InputStream inputStream,
String... includeDomainKeys)
It generates Json from properties stored in provided InputStream and will converts only included keys or parts of property keys provided by second
parameter.
|
String |
convertToJson(Map<String,String> properties)
It generates Json from given Map<String,String> instance.
|
String |
convertToJson(Map<String,String> properties,
String... includeDomainKeys)
It generates Json from given Map<String,String> instance and will converts only included keys or parts of property keys provided by second
parameter.
|
String |
convertToJson(Properties properties)
It generates Json from given Java Properties instance.
|
String |
convertToJson(Properties properties,
boolean tryConvertStringValuesToOtherObjects)
It generates Json from given Java Properties instance.
|
String |
convertToJson(Properties properties,
String... includeDomainKeys)
It generates Json from given Java Properties instance and will converts only included keys or parts of property keys provided by second parameter.
|
void |
setPropertyKeysOrderResolver(PropertyKeysOrderResolver propertyKeysOrderResolver)
It change implementation of order gathering keys from properties
|
public PropertiesToJsonConverter()
@Deprecated public PropertiesToJsonConverter(PrimitiveJsonTypeResolver<?>... customPrimitiveResolvers)
PropertiesToJsonConverterBuilder
For add order or own implementation for for TextToConcreteObjectResolver please use one of below: - and use method PropertiesToJsonConverterBuilder.onlyCustomTextToObjectResolvers(pl.jalokim.propertiestojson.resolvers.primitives.string.TextToConcreteObjectResolver<?>...) - and use
method PropertiesToJsonConverterBuilder.defaultAndCustomTextToObjectResolvers(pl.jalokim.propertiestojson.resolvers.primitives.string.TextToConcreteObjectResolver<?>...)
For add order or own implementation for for ObjectToJsonTypeConverter please use one of below: - and use method PropertiesToJsonConverterBuilder.onlyCustomObjectToJsonTypeConverters(pl.jalokim.propertiestojson.resolvers.primitives.object.ObjectToJsonTypeConverter<?>...) - and use
method PropertiesToJsonConverterBuilder.defaultAndCustomObjectToJsonTypeConverters(pl.jalokim.propertiestojson.resolvers.primitives.object.ObjectToJsonTypeConverter<?>...)
customPrimitiveResolvers - ordered listpublic PropertiesToJsonConverter(List<TextToConcreteObjectResolver<?>> toObjectsResolvers, List<ObjectToJsonTypeConverter<?>> toJsonTypeResolvers)
public PropertiesToJsonConverter(List<TextToConcreteObjectResolver<?>> toObjectsResolvers, List<ObjectToJsonTypeConverter<?>> toJsonTypeResolvers, NullToJsonTypeConverter nullToJsonConverter, TextToJsonNullReferenceResolver textToJsonNullResolver, TextToEmptyStringResolver textToEmptyStringResolver, Boolean skipNull)
public PropertiesToJsonConverter(List<TextToConcreteObjectResolver<?>> toObjectsResolvers, List<ObjectToJsonTypeConverter<?>> toJsonTypeResolvers, NullToJsonTypeConverter nullToJsonConverter, TextToJsonNullReferenceResolver textToJsonNullResolver, TextToEmptyStringResolver textToEmptyStringResolver, Boolean skipNull, Charset charset)
public String convertPropertiesFromFileToJson(String pathToFile)
TextToConcreteObjectResolver) from string value through method: TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
pathToFile - path to FileReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertPropertiesFromFileToJson(String pathToFile, String... includeDomainKeys)
TextToConcreteObjectResolver) from string
value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
pathToFile - path to FileincludeDomainKeys - domain head keys which should be parsed to json ReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertPropertiesFromFileToJson(File file)
TextToConcreteObjectResolver)
from string value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
file - file with propertiesReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertPropertiesFromFileToJson(File file, String... includeDomainKeys)
TextToConcreteObjectResolver) from string value
through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
file - file with propertiesincludeDomainKeys - domain head keys which should be parsed to json ReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(InputStream inputStream)
TextToConcreteObjectResolver)
from string value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
inputStream - InputStream with propertiesReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(InputStream inputStream, String... includeDomainKeys)
TextToConcreteObjectResolver) from string value
through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
inputStream - InputStream with propertiesincludeDomainKeys - domain head keys which should be parsed to json ReadInputException - when cannot find fileParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(Properties properties)
It will only looks for sufficient resolver, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java PropertiesParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(Properties properties, boolean tryConvertStringValuesToOtherObjects)
Properties properties = new Properties();
properties.put("root.name", "some-name");
properties.put("root.surname", "some-surname");
properties.put("root.someBoolean1", "false");
properties.put("someBoolean2", "true");
properties.put("someNumber", 3.0);
when tryConvertStringValuesToOtherObjects is true
PropertiesToJsonConverter converter = PropertiesToJsonConverterBuilder.builder()
.build();
String json = converter.convertToJson(properties, true);
then returns below json:
{
"root": {
"someBoolean1": false,
"name": "some-name",
"surname": "some-surname"
},
"someNumber": 3.0,
"someBoolean2": true
}
values someBoolean1, someBoolean2 converted to json boolean and someNumber is number json due to fact that was stored as double in properties values
when tryConvertStringValuesToOtherObjects is false
PropertiesToJsonConverter converter = PropertiesToJsonConverterBuilder.builder()
.build();
String json = converter.convertToJson(properties, false);
then returns below json:
{
"root": {
"someBoolean1": "false",
"name": "some-name",
"surname": "some-surname"
},
"someNumber": 3.0,
"someBoolean2": "true"
}
values someBoolean1, someBoolean2 stayed as json string value and someNumber still is number json due to fact that was stored as double in properties values
Every property value (when is type of String and parameter tryConvertStringValuesToOtherObjects is equals to true) will tries resolve to concrete
object by given resolvers... It will try convert to some object (number, boolean, list etc, depends on generic type of given
TextToConcreteObjectResolver)
from string value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
When property value is not type of String then will pass through that value to second phase described below.
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java PropertiestryConvertStringValuesToOtherObjects - when is true then property values are String then will be converted to other objects. When false then just
works like convertToJson(Properties)ParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(Properties properties, String... includeDomainKeys)
It will only looks for sufficient resolver, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java PropertiesincludeDomainKeys - domain head keys which should be parsed to json ParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(Map<String,String> properties)
TextToConcreteObjectResolver)
from string value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java Map with propertiesParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertToJson(Map<String,String> properties, String... includeDomainKeys)
TextToConcreteObjectResolver) from string value
through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java Map with propertiesincludeDomainKeys - domain head keys which should be parsed to json ParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertFromValuesAsObjectMap(Map<String,Object> properties)
It will only looks for sufficient resolver, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java Map with propertiesParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertFromValuesAsObjectMap(Map<String,Object> properties, boolean tryConvertStringValuesToOtherObjects)
Map<String, Object> properties = new HashMap<>();
properties.put("root.name", "some-name");
properties.put("root.surname", "some-surname");
properties.put("root.someBoolean1", "false");
properties.put("someBoolean2", "true");
properties.put("someNumber", 3.0);
when tryConvertStringValuesToOtherObjects is true
PropertiesToJsonConverter converter = PropertiesToJsonConverterBuilder.builder()
.build();
String json = converter.convertFromValuesAsObjectMap(properties, true);
then returns below json:
{
"root": {
"someBoolean1": false,
"name": "some-name",
"surname": "some-surname"
},
"someNumber": 3.0,
"someBoolean2": true
}
values someBoolean1, someBoolean2 converted to json boolean and someNumber is number json due to fact that was stored as double in properties values
when tryConvertStringValuesToOtherObjects is false
PropertiesToJsonConverter converter = PropertiesToJsonConverterBuilder.builder()
.build();
String json = converter.convertFromValuesAsObjectMap(properties, false);
then returns below json:
{
"root": {
"someBoolean1": "false",
"name": "some-name",
"surname": "some-surname"
},
"someNumber": 3.0,
"someBoolean2": "true"
}
values someBoolean1, someBoolean2 stayed as json string value and someNumber still is number json due to fact that was stored as double in properties values
Every property value (when is type of String and parameter tryConvertStringValuesToOtherObjects is equals to true) will tries resolve to concrete
object by given resolvers... It will try convert to some object (number, boolean, list etc, depends on generic type of given
TextToConcreteObjectResolver)
from string value through method:
TextToConcreteObjectResolver.returnObjectWhenCanBeResolved(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, String propertyValue, String propertyKey) The order of resolvers is important because on that depends on which resolver as
first will convert from string to some given object...
When property value is not type of String then will pass through that value to second phase described below.
Next will looks for sufficient converter, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java Map with propertiestryConvertStringValuesToOtherObjects - when is true then property values are String then will be converted to other objects. When false then just
works like convertFromValuesAsObjectMap(Map)ParsePropertiesException - when structure of properties is not compatible with json structurepublic String convertFromValuesAsObjectMap(Map<String,Object> properties, String... includeDomainKeys)
It will only looks for sufficient resolver, firstly will looks for exactly match class type, if not then will looks for closets parent class or parent
interface. If will find resolver for parent class or parent interface at the same level, then will get parent super class as first. If will find only
closets super interfaces (at the same level) then will throw exception... after successful found resolver it converts from given object to some instance
which extends AbstractJsonType through method
ObjectToJsonTypeConverter.convertToJsonTypeOrEmpty(PrimitiveJsonTypesResolver
primitiveJsonTypesResolver, Object propertyValue, String propertyKey)
properties - Java Map with propertiesincludeDomainKeys - domain head keys which should be parsed to json ParsePropertiesException - when structure of properties is not compatible with json structurepublic void setPropertyKeysOrderResolver(PropertyKeysOrderResolver propertyKeysOrderResolver)
propertyKeysOrderResolver - another implementation of get ordered properties keysCopyright © 2022. All rights reserved.