1 /*
2 * #%L
3 * This file is part of jFold.
4 * %%
5 * Copyright (C) 2012 - 2024 Mike Thomas <mikepthomas@outlook.com>
6 * %%
7 * jFold is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * %
12 * jFold is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * %
17 * You should have received a copy of the GNU General Public License
18 * along with jFold. If not, see <http://www.gnu.org/licenses/>.
19 * #L%
20 */
21 package info.mikethomas.jfold.util;
22
23 import com.fasterxml.jackson.core.json.JsonReadFeature;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule;
26
27 import lombok.experimental.UtilityClass;
28
29 /**
30 * <p>JacksonUtil class.</p>
31 *
32 * @author Michael Thomas (mikepthomas@outlook.com)
33 * @version 7.6.21
34 */
35 @UtilityClass
36 public class JacksonUtil {
37
38 private ObjectMapper mapper;
39
40 /**
41 * <p>getObjectMapper.</p>
42 *
43 * @return a {@link com.fasterxml.jackson.databind.ObjectMapper} object
44 */
45 public ObjectMapper getObjectMapper() {
46 if (mapper == null) {
47 setupMapper();
48 }
49 return mapper;
50 }
51
52 private void setupMapper() {
53 mapper = new ObjectMapper();
54 mapper.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true);
55 mapper.registerModule(new JakartaXmlBindAnnotationModule());
56 mapper.setDateFormat(DateAdapter.DATE_FORMAT);
57 }
58 }