README.md 3.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Andmemuundur README
Most of the current functionalities are related to JSON re-mapping/re-formatting
and are demonstrated in SAMPLE_REQUESTS.md file.
Most of the sample requests there use existing templates from templates folder.
For a few others extra example templates are located in templates_examples folder.

For extra information one can also refer to
src/test/java/rig/andmemuundur/service/JsonServiceTests.java which contains
tests that also demonstrate these functionalities. Input output and templates for mapping between I/O for these
test cases are in the src/test/java/rig/andmemuundur/resources/json subfolders.

Most of the basic functionality for JSON mapping/conversions can be described by  following template :
```
{
"this_will_be_field_name_in_output":{
   "$.input" :"$.this_is_field_name_in_input",
 }
}

```

For mapping arrays  some more complicated constructions are available to be used in templates :
```
{
  "array_name_in_output" : [ 
    {
      "#.input_array": "$.array_name_in_input",
      "sort_property": "$.field_from_object_in_that_array",
      "sort_type": "date",
      "sort_date_format": "yyyy-MM-dd'T'HH:mm'Z'",
      "sort_order": "desc",
      "properties": {  
        "field_name_in_array_object_in_output": "$.some_field_from_object_in_input_array", 
     }
   ]
}
```
Instead of "#.input_array" one might also see "from_property" field in templates. This should be considered
a depreciated feature. For writing future templates "#.input_array" is strongly recommended as this would
allow the same functionality and more.
For more detailed examples showing more complicated structures SAMPLE_REQUEST.md and its used templates
should be consulted. Also there are examples for data conversion functionalities at the end of this file.

Functionality of endpoint json/v1/convert that is also demonstrated in
SAMPLE_REQUESTS.md  does right now not use the general template based configuration.
Currently only conversion of HTML-string to (base64 encoded) PDF is implemented.

Fore extra information about this one can also refer to related tests
src/test/java/rig/andmemuundur/service/PdfServiceTests.java

Internal functionalities examples.Some of which are also covered  in the JSON transformations example 
in SAMPLE_REQUESTS.md.

Transform date format.
```
{
  "string_to_date": {
    "$.input": "$.aeg",
    "input_format": "dd-MM-yyyy HH:mm:ss.SSS",
    "type": "date",
    "format": "dd.MM.yyyy"
  }
}
```

Integer json to string json and vice versa 
```
{
  "int_to_string": {
    "$.input": "$.int_to_string",
    "type": "string"
  },
  "string_to_int": {
    "$.input": "$.string_to_int",
    "type": "integer"
  }
}
```

String json to decimal json, decimal json with scale,
Decimal json to string json or integer json

```
{
  "str_to_decimal": {
    "$.input": "$.str_to_decimal",
    "type": "decimal"
  },
  "str_to_decimal_scale": {
    "$.input": "$.str_to_decimal",
    "type": "decimal",
    "scale": 2
  },
  "decimal_to_str": {
    "$.input": "$.decimal_to_str",
    "type": "string"
  },
  "decimal_to_integer": {
    "$.input": "$.decimal_to_integer",
    "type": "integer"
  }
}
  ```

String json to boolean and vice versa
  ```
{
  "str_to_bln": {
    "$.input": "$.str_to_bln",
    "type": "boolean"
  },
  "bln_to_str": {
    "$.input": "$.bln_to_str",
    "type": "string"
   }
}
```