Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.internal.management;
import com.oracle.coherence.common.base.Logger;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.IntSummaryStatistics;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularDataSupport;
/**
* A utility written to make conversions of objects to REST compatible JSON value.
* The idea of the class is that any method which starts with "transform" string is a
* converter. For an input class that is provided to convert, we take the simple name
* of the class and figures out if there is a "transform" method. If one is available
* that function is called.
*
* @author sr 2017.08.21
* @since 12.2.1.4.0
*/
public class Converter
{
// ----- Converter methods ----------------------------------------------
/**
* Convert the provided Object into a REST compatible JSON object. The return type in case
* of complex objects will typically be JSONObject, or in case of arrays, it will be JSONArray.
*
* @param oObject the object which needs to be converted.
*
* @return the converted object
*/
public static Object convert(Object oObject)
{
// unfortunately, the transform logic mentioned in the class level comments did not work in few scenarios
// for example there are multiple implementations of CompositeData, TabularDataSupport etc
// so we could not call a transformCompositeData method via reflection, as the simple class
// name of the class was different
if (Objects.isNull(oObject))
{
return null;
}
Class clzObject = oObject.getClass();
if (clzObject.isArray())
{
return convertArray(oObject);
}
if (oObject instanceof CompositeData)
{
return transformCompositeData((CompositeData) oObject);
}
else if (oObject instanceof TabularDataSupport)
{
return transformTabularData((TabularDataSupport) oObject);
}
else if (oObject instanceof Map)
{
return convertMap(oObject);
}
else
{
Function