com.fasterxml.jackson.databind.type.CollectionType Java Examples

The following examples show how to use com.fasterxml.jackson.databind.type.CollectionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CollectionModelContentConverter.java    From springdoc-openapi with Apache License 2.0 7 votes vote down vote up
@Override
public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
	if (chain.hasNext() && type != null && type.getType() instanceof CollectionType
			&& "_embedded".equalsIgnoreCase(type.getPropertyName())) {
		Schema<?> schema = chain.next().resolve(type, context, chain);
		if (schema instanceof ArraySchema) {
			Class<?> entityType = getEntityType(type);
			String entityClassName = linkRelationProvider.getCollectionResourceRelFor(entityType).value();

			return new ObjectSchema()
					.name("_embedded")
					.addProperties(entityClassName, schema);
		}
	}
	return chain.hasNext() ? chain.next().resolve(type, context, chain) : null;
}
 
Example #2
Source File: TestDataProviderEngine.java    From n2o-framework with Apache License 2.0 7 votes vote down vote up
private List<DataSet> loadJson(InputStream is, PrimaryKeyType primaryKeyType, String primaryKeyFieldId) throws IOException {
    TypeFactory typeFactory = objectMapper.getTypeFactory();
    CollectionType collectionType = typeFactory.constructCollectionType(
            List.class, DataSet.class);
    List<DataSet> dataList = objectMapper.readValue(is, collectionType);
    for (DataSet data : dataList) {
        if (data.containsKey(primaryKeyFieldId) && integer.equals(primaryKeyType))
            data.put(primaryKeyFieldId, ((Number) data.get(primaryKeyFieldId)).longValue());
    }
    return dataList;
}
 
Example #3
Source File: TestDataProviderEngineTest.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteOnFile() throws IOException {
    TestDataProviderEngine engine = new TestDataProviderEngine();
    engine.setResourceLoader(new DefaultResourceLoader());
    engine.setPathOnDisk(testFolder.getRoot() + "/");

    N2oTestDataProvider provider = new N2oTestDataProvider();
    provider.setFile(testFile.getName());

    //Удаление данных
    provider.setOperation(delete);

    Map<String, Object> inParamsForDelete = new LinkedHashMap<>();
    inParamsForDelete.put("id", 1L);

    engine.invoke(provider, inParamsForDelete);

    //Проверка, что после delete, json файл содержит ожидаемые данные
    ObjectMapper objectMapper = new ObjectMapper();
    TypeFactory typeFactory = objectMapper.getTypeFactory();
    CollectionType collectionType = typeFactory.constructCollectionType(
            List.class, HashMap.class);
    List<Map> result = objectMapper.readValue(testFile, collectionType);

    assertThat(result.size(), is(0));
}
 
Example #4
Source File: DruidConnectionImpl.java    From Quicksql with MIT License 6 votes vote down vote up
/** Reads data source names from Druid. */
    Set<String> tableNames() {
        final Map<String, String> requestHeaders =
            ImmutableMap.of("Content-Type", "application/json");
        final String data = null;
        final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources";
//        if (CalcitePrepareImpl.DEBUG) {
//            System.out.println("Druid: table names" + data + "; " + url);
//        }
        try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000);
            InputStream in = traceResponse(in0)) {
            final ObjectMapper mapper = new ObjectMapper();
            final CollectionType listType =
                mapper.getTypeFactory().constructCollectionType(List.class,
                    String.class);
            final List<String> list = mapper.readValue(in, listType);
            return ImmutableSet.copyOf(list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
Example #5
Source File: RestServiceImpl.java    From peer-os with Apache License 2.0 6 votes vote down vote up
private Map<String, ContainerQuota> getChangedContainers( final String quotaContainers ) throws java.io.IOException
{
    Map<String, ContainerQuota> changedContainersFiltered = new HashMap<>();
    TypeFactory typeFactory = mapper.getTypeFactory();
    CollectionType arrayType = typeFactory.constructCollectionType( ArrayList.class, ChangedContainerDto.class );
    List<ChangedContainerDto> changedContainers = mapper.readValue( quotaContainers, arrayType );
    for ( ChangedContainerDto cont : changedContainers )
    {
        ContainerQuotaDto containerQuotaDto = cont.getQuota();
        ContainerSize containerSize = containerQuotaDto.getContainerSize();
        ContainerQuota defaultQuota = ContainerSize.getDefaultContainerQuota( containerSize );
        if ( containerSize == ContainerSize.CUSTOM )
        {
            defaultQuota = containerQuotaDto.getContainerQuota();
        }

        changedContainersFiltered.put( cont.getHostId(), defaultQuota );
    }
    return changedContainersFiltered;
}
 
Example #6
Source File: RESTServiceConnectorTest.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomDeserializerForCustomLists() throws Exception {
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(HTTP_200_STATUS_LINE);
    when(response.getEntity()).thenReturn(new StringEntity("{results: [{field : \"SomeValue\"}], results_count: 1}"));
    final CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
    when(httpClient.execute(any(HttpHost.class), any(HttpRequest.class), any(HttpClientContext.class))).thenReturn(response);
    final RestClient restClient = new BasicRestClient(httpClient, HttpClientContext.create(), "localhost");
    final Class<? extends CollectionType> clazzListOfTestPojo = new ObjectMapper().getTypeFactory().constructCollectionType(List.class, TestPojo.class).getClass();
    final RESTServiceConnector connector = new RESTServiceConnector.Builder()
        .client(restClient)
        .classToDeserializerEntry(clazzListOfTestPojo, new CustomListDeserializer<TestPojoDeserializer>())
        .build();

    connector.executeRetrieveObject(TestPojo.class, "/somepath");
}
 
Example #7
Source File: RESTServiceConnectorTest.java    From cosmic with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomDeserializerForCustomLists() throws Exception {
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(HTTP_200_STATUS_LINE);
    when(response.getEntity()).thenReturn(new StringEntity("{results: [{field : \"SomeValue\"}], results_count: 1}"));
    final CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
    when(httpClient.execute(any(HttpHost.class), any(HttpRequest.class), any(HttpClientContext.class))).thenReturn(response);
    final RestClient restClient = new BasicRestClient(httpClient, HttpClientContext.create(), "localhost");
    final Class<? extends CollectionType> clazzListOfTestPojo = new ObjectMapper().getTypeFactory().constructCollectionType(List.class, TestPojo.class).getClass();
    final RESTServiceConnector connector = new RESTServiceConnector.Builder()
            .client(restClient)
            .classToDeserializerEntry(clazzListOfTestPojo, new CustomListDeserializer<TestPojoDeserializer>())
            .build();

    connector.executeRetrieveObject(TestPojo.class, "/somepath");
}
 
Example #8
Source File: XmlParserModule.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@Override
public void setupModule(final SetupContext context) {
    super.setupModule(context);
    context.addBeanDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyCollectionDeserializer(final DeserializationConfig config,
                                                                final CollectionType type,
                                                                final BeanDescription beanDesc,
                                                                final JsonDeserializer<?> deserializer) {
            if (deserializer instanceof CollectionDeserializer) {
                return new ListDeserializer((CollectionDeserializer) deserializer);
            } else {
                return super.modifyCollectionDeserializer(config, type, beanDesc,
                        deserializer);
            }
        }
    });
}
 
Example #9
Source File: MapDeserializerManager.java    From caravan with Apache License 2.0 6 votes vote down vote up
public MapDeserializerManager(MapCustomizationFactory factory) {
  /**
   * The first parameter is just a placeholder, won't be used.
   * So any element type is ok.
   */
  super(
      CollectionType.construct(ArrayList.class, null, null, null, //
          SimpleType.constructUnsafe(Object.class)), //
      null, null, new ValueInstantiator() {
        @SuppressWarnings("rawtypes")
        @Override
        public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
          return new ArrayList();
        }
      });

  this.factory = factory;
}
 
Example #10
Source File: ContainerTest.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test
public void serderJson1() throws IOException {
    final CollectionType type = JSONTestHelper.getMapper().getTypeFactory().constructCollectionType(List.class, Container.class);

    final List<Container> containers = testRoundTrip(RemoteApiVersion.VERSION_1_22,
            "containers/json/filter1.json",
            type
    );

    assertThat(containers.size(), equalTo(1));

    final Container container = containers.get(0);

    assertThat(container.getImageId(),
            equalTo("sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efe7ec9"));
    assertThat(container.getSizeRootFs(), equalTo(1113554L));

    final ContainerHostConfig hostConfig = container.getHostConfig();
    assertThat(hostConfig, notNullValue());
    assertThat(hostConfig.getNetworkMode(), equalTo("default"));
}
 
Example #11
Source File: DruidConnectionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Reads data source names from Druid. */
Set<String> tableNames() {
  final Map<String, String> requestHeaders =
      ImmutableMap.of("Content-Type", "application/json");
  final String data = null;
  final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources";
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println("Druid: table names" + data + "; " + url);
  }
  try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000);
       InputStream in = traceResponse(in0)) {
    final ObjectMapper mapper = new ObjectMapper();
    final CollectionType listType =
        mapper.getTypeFactory().constructCollectionType(List.class,
            String.class);
    final List<String> list = mapper.readValue(in, listType);
    return ImmutableSet.copyOf(list);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #12
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
/**
 * @param logs
 * @return
 * @throws BaseException
 * @throws IOException
 */
public String decodeEventReturnJson(String logs) throws BaseException, IOException {
    // log json trans to list log
    ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
    CollectionType listType =
            mapper.getTypeFactory().constructCollectionType(ArrayList.class, Log.class);
    @SuppressWarnings("unchecked")
    List<Log> logList = (List<Log>) mapper.readValue(logs, listType);

    // decode event
    Map<String, List<List<EventResultEntity>>> resultEntityMap =
            decodeEventReturnObject(logList);
    String result = mapper.writeValueAsString(resultEntityMap);

    return result;
}
 
Example #13
Source File: APIClientTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public List<UserDataSetMetadata> listDataSets(String name) throws IOException {
    InputStream result;
    if (name == null) {
        result = when().get("/api/datasets").asInputStream();
    } else {
        result = when().get("/api/datasets?name={name}", name).asInputStream();
    }
    CollectionType resultType = //
            TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, UserDataSetMetadata.class);
    return mapper.readValue(result, resultType);
}
 
Example #14
Source File: GuavaDeserializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
private void requireCollectionOfComparableElements(CollectionType actualType, String targetType) {
    Class<?> elemType = actualType.getContentType().getRawClass();
    if (!Comparable.class.isAssignableFrom(elemType)) {
        throw new IllegalArgumentException("Can not handle " + targetType
                + " with elements that are not Comparable<?> (" + elemType.getName() + ")");
    }
}
 
Example #15
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc,
                                                      TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findCollectionDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #16
Source File: FindSerializers.java    From ameba with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public JsonSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription
        beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {

    if (Collection.class.isAssignableFrom(type.getRawClass())
            && jsonContext.isSupportedType(type.getContentType().getRawClass())) {
        return createSerializer();
    }

    return null;
}
 
Example #17
Source File: KogitoSpringObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    CollectionType collectionType = ctxt.getTypeFactory().constructCollectionType(List.class, property.getType().containedType(0));
    DataStoreDeserializer deserializer = new DataStoreDeserializer();
    deserializer.collectionType = collectionType;
    return deserializer;
}
 
Example #18
Source File: KogitoQuarkusObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    CollectionType collectionType = ctxt.getTypeFactory().constructCollectionType(List.class, property.getType().containedType(0));
    DataStoreDeserializer deserializer = new DataStoreDeserializer();
    deserializer.collectionType = collectionType;
    return deserializer;
}
 
Example #19
Source File: KogitoSpringObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual( DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    CollectionType collectionType = ctxt.getTypeFactory().constructCollectionType(List.class, property.getType().containedType(0));
    DataStreamDeserializer deserializer = new DataStreamDeserializer();
    deserializer.collectionType = collectionType;
    return deserializer;
}
 
Example #20
Source File: MyJacksonUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 非常麻烦
 *
 * @param jsonString
 * @param clazz
 * @param <T>
 * @return
 */
public static <T> List<T> parseArray(String jsonString, Class<T> clazz) {

    //注册一种类型
    // 非常麻烦 ,不同的应用,需要注册不同的类型,直接用 fast json 吧
    CollectionType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, clazz);
    try {
        return objectMapper.readValue(jsonString, javaType);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

}
 
Example #21
Source File: HtmlSerializerTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Test
public void html_serializer_with_jira_export() throws Exception {

    final SchemaParser.Request request;
    final Schema result;
    try (InputStream inputStream = this.getClass().getResourceAsStream("jira_export.xls")) {
        // We do know the format and therefore we go directly to the HTML schema guessing
        request = getRequest(inputStream, "#2");
        request.getMetadata().setEncoding("UTF-16");

        result = htmlSchemaGuesser.parse(request);
    }

    try (InputStream inputStream = this.getClass().getResourceAsStream("jira_export.xls")) {

        final List<ColumnMetadata> columns = result.getSheetContents().get(0).getColumnMetadatas();
        Assert.assertThat(columns.size(), is(98));
        request.getMetadata().getRowMetadata().setColumns(columns);

        InputStream jsonStream = htmlSerializer.serialize(inputStream, request.getMetadata(), -1);

        String json = IOUtils.toString(jsonStream, UTF_8);
        ObjectMapper mapper = new ObjectMapper();
        CollectionType collectionType =
                mapper.getTypeFactory().constructCollectionType(ArrayList.class, TreeMap.class);
        List<Map<String, String>> values = mapper.readValue(json, collectionType);
        Map<String, String> row0 = values.get(0);
        for (String s : row0.keySet()) {
            row0.put(s, row0.get(s).trim());
        }
        Assertions.assertThat(row0).contains(MapEntry.entry("0001", "TDP-1"));
    }
}
 
Example #22
Source File: MapDeserializer.java    From caravan with Apache License 2.0 5 votes vote down vote up
public MapDeserializer(JavaType pairType) {
  super(
      CollectionType.construct(ArrayList.class, null, null, null, pairType), //
      null, null, new ValueInstantiator() {
        @Override
        public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
          return new ArrayList();
        }
      });
}
 
Example #23
Source File: PCollectionsDeserializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
/**
 * We have plenty of collection types to support...
 */
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type,
        DeserializationConfig config, BeanDescription beanDesc,
        TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
    throws JsonMappingException
{
    Class<?> raw = type.getRawClass();

    // PCollection types
    if (PCollection.class.isAssignableFrom(raw)) {
        // We check these in order of most desirable to least desirable, using TreePVector as the most
        // desirable type if possible
        if (raw.isAssignableFrom(TreePVector.class)) {
            return new TreePVectorDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (raw.isAssignableFrom(ConsPStack.class)) {
            return new ConsPStackDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (raw.isAssignableFrom(MapPSet.class)) {
            return new HashTreePSetDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (raw.isAssignableFrom(OrderedPSet.class)) {
            return new OrderedPSetDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
        if (raw.isAssignableFrom(MapPBag.class)) {
            return new HashTreePBagDeserializer(type, elementTypeDeserializer, elementDeserializer);
        }
    }
    return null;
}
 
Example #24
Source File: RecentEmojiPageModel.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private LinkedHashSet<String> getPersistedCache() {
  String serialized = prefs.getString(preferenceName, "[]");
  try {
    CollectionType collectionType = TypeFactory.defaultInstance()
                                               .constructCollectionType(LinkedHashSet.class, String.class);
    return JsonUtils.getMapper().readValue(serialized, collectionType);
  } catch (IOException e) {
    Log.w(TAG, e);
    return new LinkedHashSet<>();
  }
}
 
Example #25
Source File: PCollectionsCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
protected PCollectionsCollectionDeserializer(CollectionType type,
        TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
    super(type);
    _containerType = type;
    _typeDeserializerForValue = typeDeser;
    _valueDeserializer = deser;
}
 
Example #26
Source File: CyclopsDeserializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    if (IterableX.class.isAssignableFrom(type.getRawClass())) {
        return new IterableXDeserializer(type.getRawClass(),type.containedTypeOrUnknown(0).getRawClass(),elementTypeDeserializer,elementDeserializer, type);
    }
  return super.findCollectionDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
}
 
Example #27
Source File: JsonAccountStorage.java    From chat-socket with MIT License 5 votes vote down vote up
private void load() throws IOException {
    if (!storeFile.isFile()) {
        accounts = new CopyOnWriteArrayList<>();
    } else {
        CollectionType destType = TypeFactory.defaultInstance().constructCollectionType(List.class, Account.class);
        List<Account> accounts = new ObjectMapper().readValue(storeFile, destType);
        accounts.forEach(account -> {
            account.getProfile().setId(account.getId());
            account.getProfile().setState(Profile.STATE_OFFLINE);
        });
        this.accounts = new CopyOnWriteArrayList<>(accounts);
    }
}
 
Example #28
Source File: RecentEmojiPageModel.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private LinkedHashSet<String> getPersistedCache() {
  String serialized = prefs.getString(EMOJI_LRU_PREFERENCE, "[]");
  try {
    CollectionType collectionType = TypeFactory.defaultInstance()
                                               .constructCollectionType(LinkedHashSet.class, String.class);
    return JsonUtils.getMapper().readValue(serialized, collectionType);
  } catch (IOException e) {
    Log.w(TAG, e);
    return new LinkedHashSet<>();
  }
}
 
Example #29
Source File: RecentEmojiPageModel.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private LinkedHashSet<String> getPersistedCache() {
  String serialized = prefs.getString(preferenceName, "[]");
  try {
    CollectionType collectionType = TypeFactory.defaultInstance()
                                               .constructCollectionType(LinkedHashSet.class, String.class);
    return JsonUtils.getMapper().readValue(serialized, collectionType);
  } catch (IOException e) {
    Log.w(TAG, e);
    return new LinkedHashSet<>();
  }
}
 
Example #30
Source File: ConnectionInformationSerializer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a deep copy of the given JSON Java object. Will also take care of cases where the given object is a
 * collection of objects. Note: Do not pass collections of collections, those will fail.
 *
 * @param jsonObject the input object that is serializable to JSON; will not be modified. If it contains encrypted
 *                   values, they will be passed as-is to the new copy
 * @return a object of the same type and with the same values, but technically is a completely separate object with
 * no references to the input object. Encrypted values will be the same as before
 * @throws IOException if something goes wrong during the copy or a non-JSON capable object has been provided
 */
@SuppressWarnings({"unchecked, rawtypes"})
public <T> T createDeepCopy(T jsonObject) throws IOException {
	if (jsonObject == null) {
		return null;
	}

	try {
		return AccessController.doPrivileged((PrivilegedExceptionAction<T>) () -> {
			ObjectMapper mapper = createObjectMapper();

			// we need to check if its a regular simple POJO or if it is a collection of POJOs
			Class<? extends Collection> collectionClass = Collection.class.isAssignableFrom(jsonObject.getClass()) ? (Class<? extends Collection>) jsonObject.getClass() : null;
			if (collectionClass != null) {
				Collection collection = (Collection) jsonObject;
				if (collection.isEmpty()) {
					return (T) mapper.readValue(mapper.writeValueAsString(jsonObject), jsonObject.getClass());
				} else {
					Object innerObject = collection.iterator().next();
					CollectionType collectionType = mapper.getTypeFactory().constructCollectionType(collectionClass, innerObject.getClass());
					return mapper.readValue(mapper.writeValueAsString(jsonObject), collectionType);
				}
			} else {
				return (T) mapper.readValue(mapper.writeValueAsString(jsonObject), jsonObject.getClass());
			}
		});
	} catch (PrivilegedActionException e) {
		if (e.getException() instanceof IOException) {
			throw (IOException) e.getException();
		} else if (e.getException() instanceof RuntimeException) {
			throw (RuntimeException) e.getException();
		} else {
			throw new IOException(e.getException());
		}
	}
}