• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 28515008125

01 Jul 2026 11:43AM UTC coverage: 63.785% (+0.1%) from 63.651%
28515008125

push

github

rkorytkowski
Fix @since 2.9.x to 2.9.0

24079 of 37750 relevant lines covered (63.79%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/api/src/main/java/org/openmrs/serialization/JacksonConfig.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.serialization;
11

12
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
13
import com.fasterxml.jackson.annotation.JsonTypeInfo;
14
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
15
import com.fasterxml.jackson.databind.BeanDescription;
16
import com.fasterxml.jackson.databind.DeserializationConfig;
17
import com.fasterxml.jackson.databind.DeserializationContext;
18
import com.fasterxml.jackson.databind.DeserializationFeature;
19
import com.fasterxml.jackson.databind.JavaType;
20
import com.fasterxml.jackson.databind.KeyDeserializer;
21
import com.fasterxml.jackson.databind.ObjectMapper;
22
import com.fasterxml.jackson.databind.module.SimpleKeyDeserializers;
23
import com.fasterxml.jackson.databind.module.SimpleModule;
24
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
25
import org.jspecify.annotations.NonNull;
26
import org.openmrs.OpenmrsObject;
27
import org.openmrs.util.OpenmrsJacksonLocaleModule;
28
import org.springframework.context.annotation.Bean;
29
import org.springframework.context.annotation.Configuration;
30

31
/**
32
 * Default Jackson object mapper configuration.
33
 * <p>
34
 * Used for example by {@link org.openmrs.scheduler.jobrunr.JobRunrConfig} or
35
 * {@link org.openmrs.event.outbox.OutboxEventInterceptor}.
36
 * 
37
 * @since 2.9.0
38
 */
39
@Configuration
40
public class JacksonConfig {
1✔
41

42
        @Bean
43
        public ObjectMapper objectMapper() {
44
                ObjectMapper mapper = new ObjectMapper();
1✔
45
                mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
1✔
46
                
47
                Hibernate5Module hibernate5Module = new Hibernate5Module();
1✔
48
                hibernate5Module.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING);
1✔
49
                hibernate5Module.enable(Hibernate5Module.Feature.REPLACE_PERSISTENT_COLLECTIONS);
1✔
50
                
51
                mapper.registerModule(hibernate5Module);
1✔
52
                mapper.registerModule(new OpenmrsJacksonLocaleModule());
1✔
53

54
                SimpleModule keyDeserializingModule = newKeyDeserializingModule();
1✔
55
                mapper.registerModule(keyDeserializingModule);
1✔
56

57
                // Prevent infinite recursion on bidirectional entity relationships
58
                mapper.addMixIn(OpenmrsObject.class, OpenmrsObjectMixIn.class);
1✔
59

60
                // Prevent type info serialization for Collections and Maps
61
                mapper.addMixIn(java.util.Collection.class, IgnoreTypeInfoMixIn.class);
1✔
62
                mapper.addMixIn(java.util.Map.class, IgnoreTypeInfoMixIn.class);
1✔
63

64
                return mapper;
1✔
65
        }
66

67
        /**
68
         * Allows to deserialize Maps that have OpenmrsObjects as keys.
69
         * @return module
70
         */
71
        private static @NonNull SimpleModule newKeyDeserializingModule() {
72
                SimpleModule openmrsModule = new SimpleModule();
1✔
73
                openmrsModule.setKeyDeserializers(new SimpleKeyDeserializers() {
1✔
74
                        @Override
75
                        public KeyDeserializer findKeyDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) {
76
                                if (OpenmrsObject.class.isAssignableFrom(type.getRawClass())) {
1✔
77
                                        return new KeyDeserializer() {
1✔
78
                                                @Override
79
                                                public Object deserializeKey(String key, DeserializationContext ctxt) {
80
                                                        try {
81
                                                                OpenmrsObject obj = (OpenmrsObject) type.getRawClass().getDeclaredConstructor().newInstance();
×
82
                                                                obj.setUuid(key);
×
83
                                                                return obj;
×
84
                                                        } catch (Exception e) {
×
85
                                                                return null;
×
86
                                                        }
87
                                                }
88
                                        };
89
                                }
90
                                return null;
1✔
91
                        }
92
                });
93
                return openmrsModule;
1✔
94
        }
95

96
        @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
97
        public abstract static class OpenmrsObjectMixIn {
×
98
        }
99

100
        @JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
101
        public abstract static class IgnoreTypeInfoMixIn {
×
102
        }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc