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

trydofor / professional-wings / #140

08 Feb 2025 09:13AM UTC coverage: 63.606% (-0.08%) from 63.687%
#140

push

web-flow
Merge pull request #316 from trydofor/develop

release of 3.3.140

242 of 343 new or added lines in 58 files covered. (70.55%)

55 existing lines in 6 files now uncovered.

12926 of 20322 relevant lines covered (63.61%)

0.64 hits per line

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

90.91
/wings/slardar/src/main/java/pro/fessional/wings/slardar/jackson/I18nStringSerializer.java
1
package pro.fessional.wings.slardar.jackson;
2

3
import com.fasterxml.jackson.core.JsonGenerator;
4
import com.fasterxml.jackson.databind.BeanProperty;
5
import com.fasterxml.jackson.databind.JsonSerializer;
6
import com.fasterxml.jackson.databind.SerializerProvider;
7
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
8
import lombok.RequiredArgsConstructor;
9
import pro.fessional.mirana.data.Null;
10
import pro.fessional.mirana.i18n.I18nAware.I18nSource;
11
import pro.fessional.mirana.i18n.I18nString;
12
import pro.fessional.wings.slardar.autodto.AutoI18nString;
13
import pro.fessional.wings.slardar.context.LocaleZoneIdUtil;
14

15
import java.io.IOException;
16
import java.util.Locale;
17
import java.util.concurrent.atomic.AtomicReference;
18

19
/**
20
 * @author trydofor
21
 * @since 2019-09-19
22
 */
23
@RequiredArgsConstructor
24
public class I18nStringSerializer extends JsonSerializer<Object> implements ContextualSerializer {
25

26
    private final AtomicReference<I18nStringSerializer> oppositeOne = new AtomicReference<>();
27
    private final I18nSource i18nSource;
28
    private final boolean enabled;
29

30
    @Override
31
    public void serialize(Object value, JsonGenerator generator, SerializerProvider provider) throws IOException {
32

33
        if (!(value instanceof CharSequence) && !(value instanceof I18nString)) {
1✔
34
            provider.defaultSerializeValue(value, generator);
×
35
            return;
×
36
        }
37

38
        if (value instanceof CharSequence) {
1✔
39
            String text = value.toString();
1✔
40
            if (enabled) {
1✔
41
                Locale locale = LocaleZoneIdUtil.LocaleNonnull();
1✔
42
                text = i18nSource.getMessage(text, Null.Objects, text, locale);
1✔
43
            }
44
            generator.writeString(text);
1✔
45
        }
1✔
46
        else { // value instanceof I18nString
47
            I18nString i18n = (I18nString) value;
1✔
48
            if (enabled) {
1✔
49
                Locale locale = LocaleZoneIdUtil.LocaleNonnull();
1✔
50
                String text = i18n.toString(locale, i18nSource);
1✔
51
                if (text == null || text.equalsIgnoreCase(i18n.getI18nCode())) {
1✔
NEW
52
                    text = i18n.toString();
×
53
                }
54
                generator.writeString(text);
1✔
55
            }
1✔
56
            else {
57
                generator.writeStartObject();
1✔
58
                generator.writeStringField("code", i18n.getI18nCode());
1✔
59
                generator.writeStringField("hint", i18n.getI18nHint());
1✔
60
                generator.writeFieldName("args");
1✔
61
                generator.writeObject(i18n.getI18nArgs());
1✔
62
                generator.writeEndObject();
1✔
63
            }
64
        }
65
    }
1✔
66

67
    @Override
68
    public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) {
69
        if (property == null) return this;
1✔
70
        AutoI18nString ann = property.getAnnotation(AutoI18nString.class);
1✔
71
        if (ann == null || ann.value() == enabled) return this;
1✔
72

73
        I18nStringSerializer that = oppositeOne.get();
1✔
74
        // No sync required, no impact on results
75
        if (that == null) {
1✔
76
            that = new I18nStringSerializer(i18nSource, !enabled);
1✔
77
            oppositeOne.set(that);
1✔
78
        }
79
        return that;
1✔
80
    }
81
}
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