| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you 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 org.apache.directory.scim.server.rest; |
| |
| import com.fasterxml.jackson.annotation.JsonInclude; |
| import com.fasterxml.jackson.databind.DeserializationFeature; |
| import com.fasterxml.jackson.databind.ObjectMapper; |
| import com.fasterxml.jackson.databind.module.SimpleModule; |
| import org.apache.directory.scim.server.schema.Registry; |
| import org.apache.directory.scim.spec.resources.ScimResource; |
| |
| import jakarta.enterprise.inject.Produces; |
| import jakarta.inject.Inject; |
| import jakarta.ws.rs.ext.Provider; |
| |
| /** |
| * Creates and configures an {@link ObjectMapper} used for {@code application/scim+json} parsing. |
| */ |
| @Provider |
| public class ObjectMapperFactory { |
| |
| private final Registry registry; |
| |
| @Inject |
| public ObjectMapperFactory(Registry registry) { |
| this.registry = registry; |
| } |
| |
| @Produces |
| public ObjectMapper createObjectMapper() { |
| |
| ObjectMapper objectMapper = org.apache.directory.scim.spec.json.ObjectMapperFactory.getObjectMapper(); |
| objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); |
| |
| SimpleModule module = new SimpleModule(); |
| module.addDeserializer(ScimResource.class, new ScimResourceDeserializer(registry, objectMapper)); |
| objectMapper.registerModule(module); |
| |
| return objectMapper; |
| } |
| } |