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

wistefan / ngsi-ld-java-mapping / #309

13 Aug 2025 06:51AM UTC coverage: 76.533% (+0.2%) from 76.344%
#309

Pull #90

wistefan
escape reserved words
Pull Request #90: escape reserved words

10 of 11 new or added lines in 3 files covered. (90.91%)

41 existing lines in 1 file now uncovered.

649 of 848 relevant lines covered (76.53%)

0.77 hits per line

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

88.89
/src/main/java/io/github/wistefan/mapping/ReservedWordHandler.java
1
package io.github.wistefan.mapping;
2

3
import java.util.List;
4

5
/**
6
 * Handler for reserved words in NGSI-LD
7
 */
NEW
8
public class ReservedWordHandler {
×
9

10
        /**
11
         * Words that have a special meaning in NGSI-LD and are not allowed to be used in non-compliant ways.
12
         */
13
        private static final List<String> RESERVED_WORDS = List.of("id", "@id", "value", "@value", "type", "@type");
1✔
14

15
        /**
16
         * Prefix to be used for escaping the reserved words.
17
         */
18
        private static final String ESCAPE_PREFIX = "tmfEscaped-";
19

20
        /**
21
         * Escape reserved words in keys.
22
         *
23
         * @param unmappedProperty the property to escape
24
         * @return the escaped property
25
         */
26
        public static UnmappedProperty escapeReservedWords(UnmappedProperty unmappedProperty) {
27
                if (RESERVED_WORDS.contains(unmappedProperty.getName())) {
1✔
28
                        unmappedProperty.setName(String.format("%s%s", ESCAPE_PREFIX, unmappedProperty.getName()));
1✔
29
                }
30
                return unmappedProperty;
1✔
31
        }
32

33
        /**
34
         * Check if the unmapped property is an reserved word property
35
         *
36
         * @param unmappedProperty the property to check
37
         * @return true if the key is a reserved word
38
         */
39
        public static boolean isReservedProperty(UnmappedProperty unmappedProperty) {
40
                return unmappedProperty.getName().startsWith(ESCAPE_PREFIX);
1✔
41
        }
42

43
        /**
44
         * Removes the escape prefix from the property
45
         *
46
         * @param unmappedProperty the property to clean
47
         * @return the cleaned property
48
         */
49
        public static UnmappedProperty removeEscape(UnmappedProperty unmappedProperty) {
50
                if (isReservedProperty(unmappedProperty)) {
1✔
51
                        unmappedProperty.setName(unmappedProperty.getName().replaceFirst(ESCAPE_PREFIX, ""));
1✔
52
                }
53
                return unmappedProperty;
1✔
54
        }
55
}
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

© 2025 Coveralls, Inc