All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.restassured.internal.path.json.mapping.JsonPathJackson1ObjectDeserializer.groovy Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Copyright 2019 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
 *
 *        http://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 io.restassured.internal.path.json.mapping

import io.restassured.common.mapper.ObjectDeserializationContext
import io.restassured.path.json.mapper.factory.Jackson1ObjectMapperFactory
import io.restassured.path.json.mapping.JsonPathObjectDeserializer
import org.codehaus.jackson.type.JavaType

import java.lang.reflect.Type

class JsonPathJackson1ObjectDeserializer implements JsonPathObjectDeserializer {

  private final Jackson1ObjectMapperFactory factory;

  JsonPathJackson1ObjectDeserializer(Jackson1ObjectMapperFactory factory) {
    this.factory = factory
  }

  private org.codehaus.jackson.map.ObjectMapper createJacksonObjectMapper(Type cls, String charset) {
    return factory.create(cls, charset)
  }

  @Override
  def deserialize(ObjectDeserializationContext ctx) {
    def object = ctx.getDataToDeserialize().asString()
    def cls = ctx.getType()
    def mapper = createJacksonObjectMapper(cls, ctx.getCharset())
    JavaType javaType = mapper.constructType(cls)
    mapper.readValue(object, javaType)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy