public class ObjectConverterDefault extends Object implements ObjectConverter
| Constructor and Description |
|---|
ObjectConverterDefault(JsonManager jsonManager) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Object valueToCompare,
Object compareTo)
Compare two elements.
|
byte[] |
convertBase64StringToByteArray(Object object)
Converts the element to a
BigDecimal. |
String |
convertByteArrayToBase64String(byte[] byteArray)
Converts the element to a
Base64 String. |
<T> T |
convertTo(Object object,
Class<T> targetType)
Tries to convert the element to the specified
targetType. |
BigDecimal |
convertToBigDecimal(Object object)
Converts the element to a
BigDecimal. |
Boolean |
convertToBoolean(Object object)
Converts the element to a
JsonArray. |
Date |
convertToDateFromJsonDateFormat(Object object)
Converts the element to a
Date. |
Double |
convertToDouble(Object object)
Converts the element to a
Double. |
Float |
convertToFloat(Object object)
Converts the element to a
Float. |
Integer |
convertToInteger(Object object)
Converts the element to a
Integer. |
JsonArray |
convertToJsonArray(Object object)
Converts the element to a
JsonArray. |
String |
convertToJsonDateFormat(Date date)
Converts the date to a String representaiton compatible with
the Json specification.
|
JsonObject |
convertToJsonObject(Object object)
Converts the element to a
JsonObject. |
Long |
convertToLong(Object object)
Converts the element to a
Long. |
String |
convertToString(Object object)
Converts the element to a
JsonObject. |
protected JsonManager |
getJsonManager() |
boolean |
isAtLeastOneEquivalentElementInCommon(Collection<?> col1,
Collection<?> col2)
Do the two Collections have at least one equivalent element
in common?
|
boolean |
isBase64StringOrNull(Object object)
Returns
true if the element is a valid base 64 String,
or is null. |
boolean |
isCanBeConvertedTo(Class<?> referenceType,
Object elementToValidate)
Can the element be converted to the specified
referenceType? |
boolean |
isCanBeConvertedToBigDecimal(Object object)
Can the element be converted to a
BigDecimal? |
boolean |
isCanBeConvertedToBoolean(Object object)
Can the element be converted to a
Boolean? |
boolean |
isCanBeConvertedToByteArray(Object object)
Can the element be converted to a
byte[]? |
boolean |
isCanBeConvertedToDateFromJsonDateFormat(Object object)
Can the element be converted to a
Date? The source element must follow
the Json date format. |
boolean |
isCanBeConvertedToDouble(Object object)
Can the element be converted to a
Double? |
boolean |
isCanBeConvertedToFloat(Object object)
Can the element be converted to a
Float? |
boolean |
isCanBeConvertedToInteger(Object object)
Can the element be converted to a
Integer? |
boolean |
isCanBeConvertedToJsonArray(Object object)
Can the element be converted to a
JsonArray? |
boolean |
isCanBeConvertedToJsonObject(Object object)
Can the element be converted to a
JsonObject? |
boolean |
isCanBeConvertedToLong(Object object)
Can the element be converted to a
Long? |
boolean |
isCanBeConvertedToString(Object object)
Can the element be converted to a
String? |
boolean |
isEquivalent(Object valueToCompare,
Object compareTo)
Are the two elements equivalent?
|
@Inject public ObjectConverterDefault(JsonManager jsonManager)
protected JsonManager getJsonManager()
public boolean isCanBeConvertedTo(Class<?> referenceType, Object elementToValidate)
ObjectConverterreferenceType?isCanBeConvertedTo in interface ObjectConverterpublic boolean isCanBeConvertedToString(Object object)
ObjectConverterString?isCanBeConvertedToString in interface ObjectConverterpublic boolean isCanBeConvertedToInteger(Object object)
ObjectConverterInteger?isCanBeConvertedToInteger in interface ObjectConverterpublic boolean isCanBeConvertedToLong(Object object)
ObjectConverterLong?isCanBeConvertedToLong in interface ObjectConverterpublic boolean isCanBeConvertedToFloat(Object object)
ObjectConverterFloat?isCanBeConvertedToFloat in interface ObjectConverterpublic boolean isCanBeConvertedToDouble(Object object)
ObjectConverterDouble?isCanBeConvertedToDouble in interface ObjectConverterpublic boolean isCanBeConvertedToBoolean(Object object)
ObjectConverterBoolean?isCanBeConvertedToBoolean in interface ObjectConverterpublic boolean isCanBeConvertedToBigDecimal(Object object)
ObjectConverterBigDecimal?isCanBeConvertedToBigDecimal in interface ObjectConverterpublic boolean isCanBeConvertedToByteArray(Object object)
ObjectConverterbyte[]?isCanBeConvertedToByteArray in interface ObjectConverterpublic boolean isCanBeConvertedToDateFromJsonDateFormat(Object object)
ObjectConverterDate? The source element must follow
the Json date format.isCanBeConvertedToDateFromJsonDateFormat in interface ObjectConverterpublic boolean isCanBeConvertedToJsonObject(Object object)
ObjectConverterJsonObject?isCanBeConvertedToJsonObject in interface ObjectConverterpublic boolean isCanBeConvertedToJsonArray(Object object)
ObjectConverterJsonArray?isCanBeConvertedToJsonArray in interface ObjectConverterpublic boolean isBase64StringOrNull(Object object)
ObjectConvertertrue if the element is a valid base 64 String,
or is null.isBase64StringOrNull in interface ObjectConverterpublic JsonObject convertToJsonObject(Object object)
ObjectConverterJsonObject.convertToJsonObject in interface ObjectConverterpublic JsonArray convertToJsonArray(Object object)
ObjectConverterJsonArray.convertToJsonArray in interface ObjectConverterpublic String convertToString(Object object)
ObjectConverterJsonObject.convertToString in interface ObjectConverterpublic Integer convertToInteger(Object object) throws CantConvertException
ObjectConverterInteger.
The toString() method will be called on the object
before trying to convert it to an Integer. If the resulting
String contains zeros only decimals, those will be
removed and the conversion will work.
For example : "123.0" will work.
convertToInteger in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public Long convertToLong(Object object) throws CantConvertException
ObjectConverterLong.
The toString() method will be called on the object
before trying to convert it to a Long. If the resulting
String contains zeros only decimals, those will be
removed and the conversion will work.
For example : "123.0" will work.
convertToLong in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public Float convertToFloat(Object object) throws CantConvertException
ObjectConverterFloat.convertToFloat in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public Double convertToDouble(Object object) throws CantConvertException
ObjectConverterDouble.convertToDouble in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public Boolean convertToBoolean(Object object) throws CantConvertException
ObjectConverterJsonArray.
Il can be converted to a Boolean if its already a Boolean,
if it's null or if it's the String "true" or the String
"false".
convertToBoolean in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public BigDecimal convertToBigDecimal(Object object) throws CantConvertException
ObjectConverterBigDecimal.convertToBigDecimal in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public byte[] convertBase64StringToByteArray(Object object) throws CantConvertException
ObjectConverterBigDecimal.
Can be converted to a byte[] if its already a byte[],
if it's null or if it's a valid base 64 String.
convertBase64StringToByteArray in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public String convertByteArrayToBase64String(byte[] byteArray)
ObjectConverterBase64 String.convertByteArrayToBase64String in interface ObjectConverterpublic Date convertToDateFromJsonDateFormat(Object object) throws CantConvertException
ObjectConverterDate.
The source element must follow the Json date format.
convertToDateFromJsonDateFormat in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public <T> T convertTo(Object object, Class<T> targetType) throws CantConvertException
ObjectConvertertargetType.
By default, only the types native to JsonObject are supported as the target types.
convertTo in interface ObjectConverterCantConvertException - if the element can't be converted to
the required type.public String convertToJsonDateFormat(Date date)
ObjectConverterconvertToJsonDateFormat in interface ObjectConverterpublic int compareTo(Object valueToCompare, Object compareTo) throws CantCompareException
ObjectConverter
If required, try to convert the elementToCompare so it
can be compared with compareTo. It is also possible
that we have to convert compareTo, for the comparison
to be possible. For example, if compareTo is Long(10) and
elementToCompare is BigDecimal(12.34), we have to convert
both elements to BigDecimal so they can be compared.
For a comparison to work, the two elements must be (after conversion
or not) of the same type and this type must implement
Comparable.
compareTo in interface ObjectConverterCantCompareException - if the elements can't be compared together.public boolean isEquivalent(Object valueToCompare, Object compareTo)
ObjectConverter
If required, try to convert the elementToCompare so it
can be compared with compareTo. It is also possible
that we have to convert compareTo, for the comparison
to be possible. For example, if compareTo is Long(10) and
elementToCompare is BigDecimal(12.34), we have to convert
both elements to BigDecimal so they can be compared.
For the two elements to be equivalent, they must be (after conversion
or not) of the same type and then the Object.equals(Object)
method must return true.
isEquivalent in interface ObjectConverterpublic boolean isAtLeastOneEquivalentElementInCommon(Collection<?> col1, Collection<?> col2)
ObjectConverterisAtLeastOneEquivalentElementInCommon in interface ObjectConverter#isEquivalent(Object, Object)}Copyright © 2016. All rights reserved.