Search in sources :

Example 1 with SimpleModule

use of org.codehaus.jackson.map.module.SimpleModule in project apex-core by apache.

the class StramWebServices method init.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void init() {
    //clear content type
    httpResponse.setContentType(null);
    if (!initialized) {
        Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
        StringCodecs.loadConverters(codecs);
        if (codecs != null) {
            SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
            for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
                try {
                    final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance();
                    sm.addSerializer(new SerializerBase(entry.getKey()) {

                        @Override
                        public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
                            jgen.writeString(codec.toString(value));
                        }
                    });
                } catch (Exception ex) {
                    LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
                }
            }
            objectMapper.registerModule(sm);
        }
        initialized = true;
    }
}
Also used : SerializerBase(org.codehaus.jackson.map.ser.std.SerializerBase) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.codehaus.jettison.json.JSONException) StringCodec(com.datatorrent.api.StringCodec) Version(org.codehaus.jackson.Version) JsonGenerator(org.codehaus.jackson.JsonGenerator) JSONObject(org.codehaus.jettison.json.JSONObject) SerializerProvider(org.codehaus.jackson.map.SerializerProvider) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 2 with SimpleModule

use of org.codehaus.jackson.map.module.SimpleModule in project oxTrust by GluuFederation.

the class BulkWebService method deserializeToUser.

private User deserializeToUser(String dataString) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    SimpleModule simpleModule = new SimpleModule("DeserializeToUserModule", new Version(1, 0, 0, ""));
    simpleModule.addDeserializer(User.class, new UserDeserializer());
    mapper.registerModule(simpleModule);
    return mapper.readValue(dataString, User.class);
}
Also used : UserDeserializer(org.gluu.oxtrust.service.scim2.jackson.custom.UserDeserializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 3 with SimpleModule

use of org.codehaus.jackson.map.module.SimpleModule in project oxTrust by GluuFederation.

the class GroupWebService method serializeToJson.

private String serializeToJson(Object object, String attributesArray) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule customScimFilterModule = new SimpleModule("CustomScim2GroupFilterModule", new Version(1, 0, 0, ""));
    ListResponseGroupSerializer serializer = new ListResponseGroupSerializer();
    serializer.setAttributesArray(attributesArray);
    customScimFilterModule.addSerializer(Group.class, serializer);
    mapper.registerModule(customScimFilterModule);
    return mapper.writeValueAsString(object);
}
Also used : Version(org.codehaus.jackson.Version) ListResponseGroupSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseGroupSerializer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 4 with SimpleModule

use of org.codehaus.jackson.map.module.SimpleModule in project oxTrust by GluuFederation.

the class UserDeserializer method deserialize.

@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    log.info(" deserialize() ");
    try {
        JsonNode rootNode = jsonParser.readValueAsTree();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
        User user = mapper.readValue(rootNode.toString(), User.class);
        if (user.getSchemas() == null) {
            throw new IllegalArgumentException("Required field \"schemas\" is null or missing.");
        } else if (!user.getSchemas().contains(Constants.USER_CORE_SCHEMA_ID)) {
            throw new IllegalArgumentException("User Core schema is required.");
        } else if (user.getSchemas().contains(Constants.USER_EXT_SCHEMA_ID)) {
            JsonNode userExtensionNode = rootNode.get(Constants.USER_EXT_SCHEMA_ID);
            if (userExtensionNode != null) {
                ExtensionDeserializer deserializer = new ExtensionDeserializer();
                deserializer.setId(Constants.USER_EXT_SCHEMA_ID);
                SimpleModule deserializerModule = new SimpleModule("ExtensionDeserializerModule", new Version(1, 0, 0, ""));
                deserializerModule.addDeserializer(Extension.class, deserializer);
                mapper.registerModule(deserializerModule);
                Extension extension = mapper.readValue(userExtensionNode.toString(), Extension.class);
                user.addExtension(extension);
            } else {
                throw new IllegalArgumentException("User Extension schema is indicated, but value body is absent.");
            }
        }
        return user;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.Extension) User(org.gluu.oxtrust.model.scim2.User) Version(org.codehaus.jackson.Version) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) IOException(java.io.IOException)

Example 5 with SimpleModule

use of org.codehaus.jackson.map.module.SimpleModule in project oxTrust by GluuFederation.

the class FidoDeviceCoreLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule userCoreLoadingStrategyModule = new SimpleModule("FidoDeviceCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeFidoDeviceSerializer serializer = new SchemaTypeFidoDeviceSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(FidoDevice.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyFidoDevice());
    return serializer.getSchemaType();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaTypeFidoDeviceSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeFidoDeviceSerializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Aggregations

Version (org.codehaus.jackson.Version)15 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)15 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)14 IOException (java.io.IOException)3 URI (java.net.URI)3 DefaultValue (javax.ws.rs.DefaultValue)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)3 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 JsonNode (org.codehaus.jackson.JsonNode)2 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)2 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2