Skip to content

Commit cfcb19b

Browse files
committed
Update version to 1.10.0
Add id field to attributes (more usable for api clients)
1 parent c86f7b6 commit cfcb19b

5 files changed

Lines changed: 40 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.10.0] - 2023-02-21
4+
### Changed:
5+
- Add id field to attributes (more usable for api clients)
6+
- Update all dependencies versions
7+
38
## [1.9.0] - 2022-11-07
49
### Added:
510
- Trace object with id field to meta object

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ Add dependency to your project:
1616
<dependency>
1717
<groupId>com.slm-dev</groupId>
1818
<artifactId>jsonapi-simple</artifactId>
19-
<version>1.9.0</version>
19+
<version>1.10.0</version>
2020
</dependency>
2121
```
2222

23+
> **Warning:**
24+
> The id field is included in the attributes because it more convenient for API clients.
25+
2326
### Build Response
2427

2528
See documentation part: [response structure](https://jsonapi.org/format/#document-structure)
@@ -100,6 +103,7 @@ This produces response like:
100103
"type":"some-data-type",
101104
"id":"<random-uuid-id> or <fixed-id>",
102105
"attributes": {
106+
"id":"<random-uuid-id> or <fixed-id>",
103107
"name": "Test string"
104108
},
105109
"links": {
@@ -376,6 +380,7 @@ public class Test {
376380
"type":"test-object",
377381
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
378382
"attributes": {
383+
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
379384
"name":"Test string",
380385
"createDate":"2019-10-08T18:46:53.40297"
381386
},
@@ -433,6 +438,7 @@ public class Test {
433438
"type":"test-object",
434439
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
435440
"attributes": {
441+
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
436442
"name":"Test string 1",
437443
"createDate":"2019-10-08T18:46:53"
438444
},
@@ -441,7 +447,8 @@ public class Test {
441447
}
442448
},
443449
{
444-
"type":"test-object",
450+
"type":"test-object",
451+
"id":"b4070518-e9fc-11e9-81b4-2a2ae2dbcce4",
445452
"attributes": {
446453
"id":"b4070518-e9fc-11e9-81b4-2a2ae2dbcce4",
447454
"name":"Test string 2",
@@ -602,6 +609,7 @@ public class Test {
602609
"type":"test-object",
603610
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
604611
"attributes": {
612+
"id":"7a543e90-2961-480e-b1c4-51249bf0c566",
605613
"name":"Test string",
606614
"createDate":"2019-10-08T18:46:53.40297"
607615
},

pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.slm-dev</groupId>
66
<artifactId>jsonapi-simple</artifactId>
7-
<version>1.9.0</version>
7+
<version>1.10.0</version>
88
<name>jsonapi-simple</name>
99
<description>Simple implementation of the JSON:API specification</description>
1010
<url>https://slm-dev.com/jsonapi-simple/</url>
@@ -35,22 +35,22 @@
3535
<properties>
3636
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3737
<java.version>11</java.version>
38-
<spring.web.version>5.3.23</spring.web.version>
39-
<spring.data.commons.version>2.7.5</spring.data.commons.version>
40-
<lombok.version>1.18.24</lombok.version>
38+
<spring.web.version>5.3.25</spring.web.version>
39+
<spring.data.commons.version>2.7.8</spring.data.commons.version>
40+
<lombok.version>1.18.26</lombok.version>
4141
<lombok.maven.plugin.version>1.18.20.0</lombok.maven.plugin.version>
42-
<jackson.version>2.13.4.2</jackson.version>
43-
<jackson.datatype.version>2.13.4</jackson.datatype.version>
44-
<sprinfox.version>3.0.0</sprinfox.version>
45-
<junit.version>5.9.0</junit.version>
42+
<jackson.version>2.14.2</jackson.version>
43+
<jackson.datatype.version>2.14.2</jackson.datatype.version>
44+
<springfox.version>3.0.0</springfox.version>
45+
<junit.version>5.9.2</junit.version>
4646
<hamcrest.version>2.2</hamcrest.version>
47-
<mockito.version>4.8.0</mockito.version>
47+
<mockito.version>5.1.1</mockito.version>
4848
<maven.compiler.version>3.10.1</maven.compiler.version>
4949
<maven.surefire.version>2.22.2</maven.surefire.version>
5050
<maven.deploy.version>2.8.2</maven.deploy.version>
51-
<nexus.staging.maven.version>1.6.12</nexus.staging.maven.version>
51+
<nexus.staging.maven.version>1.6.13</nexus.staging.maven.version>
5252
<maven.source.version>3.2.1</maven.source.version>
53-
<maven.javadoc.version>3.4.1</maven.javadoc.version>
53+
<maven.javadoc.version>3.5.0</maven.javadoc.version>
5454
<maven.gpg.version>3.0.1</maven.gpg.version>
5555
</properties>
5656

@@ -88,7 +88,7 @@
8888
<dependency>
8989
<groupId>io.springfox</groupId>
9090
<artifactId>springfox-swagger2</artifactId>
91-
<version>${sprinfox.version}</version>
91+
<version>${springfox.version}</version>
9292
</dependency>
9393

9494
<dependency>

src/main/java/com/slmdev/jsonapi/simple/response/Data.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.slmdev.jsonapi.simple.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
43
import com.fasterxml.jackson.annotation.JsonInclude;
54
import lombok.AllArgsConstructor;
65
import lombok.Getter;
@@ -15,7 +14,6 @@
1514
public class Data<T> {
1615
private String type;
1716
private String id;
18-
@JsonIgnoreProperties({"id"})
1917
private T attributes;
2018
private Link links;
2119

src/test/java/com/slmdev/jsonapi/simple/response/ResponseTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import java.util.UUID;
2020

2121
import static org.hamcrest.MatcherAssert.assertThat;
22-
import static org.hamcrest.Matchers.is;
23-
import static org.hamcrest.Matchers.nullValue;
22+
import static org.hamcrest.Matchers.*;
2423

2524
public class ResponseTest {
2625
private static final String TEST_RESPONSE_URI = "/api/v1";
@@ -58,7 +57,7 @@ public void shouldReturnResponseWithDataAs1ObjectWithoutErrorsAndUriSpecified()
5857
assertThat(response.getMeta().getPage().getMaxSize(), is(25));
5958
assertThat(response.getMeta().getPage().getTotal(), is(1L));
6059

61-
assertThatAttributesIdFieldIsAbsentInObject(response);
60+
assertThatAttributesIdFieldIsPresentInObject(response);
6261
}
6362

6463
@Test
@@ -92,7 +91,7 @@ public void shouldReturnResponseWithDataListWithoutErrorsAndUriSpecified() {
9291
assertThat(response.getMeta().getPage().getMaxSize(), is(25));
9392
assertThat(response.getMeta().getPage().getTotal(), is(2L));
9493

95-
assertThatAttributesIdFieldIsAbsentInCollection(response);
94+
assertThatAttributesIdFieldIsPresentInCollection(response);
9695
}
9796

9897
@Test
@@ -116,7 +115,7 @@ public void shouldReturnResponseWithDataAndUriSpecifiedWithoutUriPlaceholdersAnd
116115
assertThat(response.getMeta().getPage().getMaxSize(), is(25));
117116
assertThat(response.getMeta().getPage().getTotal(), is(1L));
118117

119-
assertThatAttributesIdFieldIsAbsentInObject(response);
118+
assertThatAttributesIdFieldIsPresentInObject(response);
120119
}
121120

122121
@Test
@@ -143,7 +142,7 @@ public void shouldReturnResponseWithDataAndUriSpecifiedAndUriPlaceholdersWithout
143142
assertThat(response.getMeta().getPage().getMaxSize(), is(25));
144143
assertThat(response.getMeta().getPage().getTotal(), is(1L));
145144

146-
assertThatAttributesIdFieldIsAbsentInObject(response);
145+
assertThatAttributesIdFieldIsPresentInObject(response);
147146
}
148147

149148

@@ -373,15 +372,15 @@ public void shouldParseJsonResponseWithListData() {
373372

374373
assertThat(response.getData().get(0).getType(), is("cars"));
375374
assertThat(response.getData().get(0).getId(), is("M5"));
376-
assertThat(response.getData().get(0).getAttributes().getId(), nullValue());
377375
assertThat(response.getData().get(0).getAttributes().getBrand(), is("BMW"));
378376

379377
assertThat(response.getData().get(1).getType(), is("cars"));
380378
assertThat(response.getData().get(1).getId(), is("911"));
381-
assertThat(response.getData().get(1).getAttributes().getId(), nullValue());
382379
assertThat(response.getData().get(1).getAttributes().getBrand(), is("Porshe"));
383380

384381
assertThat(response.getMeta().getApi().getVersion(), is("1"));
382+
383+
assertThatAttributesIdFieldIsPresentInCollection(response);
385384
}
386385

387386
@Test
@@ -410,10 +409,11 @@ public void shouldParseJsonResponseWithSingleObjectData() {
410409

411410
assertThat(response.getData().getType(), is("cars"));
412411
assertThat(response.getData().getId(), is("M5"));
413-
assertThat(response.getData().getAttributes().getId(), nullValue());
414412
assertThat(response.getData().getAttributes().getBrand(), is("BMW"));
415413

416414
assertThat(response.getMeta().getApi().getVersion(), is("1"));
415+
416+
assertThatAttributesIdFieldIsPresentInObject(response);
417417
}
418418

419419
@lombok.Data
@@ -519,27 +519,27 @@ private void assertErrorResponse(final @NonNull Response<?> response) {
519519
}
520520

521521
@SuppressWarnings("unchecked")
522-
private void assertThatAttributesIdFieldIsAbsentInCollection(final @NonNull Response<List<Data<TestDto>>> response) {
522+
private void assertThatAttributesIdFieldIsPresentInCollection(final @NonNull Object response) {
523523
final Map<String, Object> responseMap = objectMapper.convertValue(response, Map.class);
524524

525525
((List<Object>)responseMap.get("data")).forEach(dataItem -> {
526526
final Object idAttributeField = ((Map<String, Object>)((Map<String, Object>)dataItem)
527527
.get("attributes"))
528528
.get("id");
529529

530-
assertThat(idAttributeField, nullValue());
530+
assertThat(idAttributeField, notNullValue());
531531
});
532532
}
533533

534534
@SuppressWarnings("unchecked")
535-
private void assertThatAttributesIdFieldIsAbsentInObject(final @NonNull Response<Data<TestDto>> response) {
535+
private void assertThatAttributesIdFieldIsPresentInObject(final @NonNull Object response) {
536536
final Map<String, Object> responseMap = objectMapper.convertValue(response, Map.class);
537537

538538
final Object idAttributeField = ((Map<String, Object>)((Map<String, Object>)responseMap
539539
.get("data"))
540540
.get("attributes"))
541541
.get("id");
542542

543-
assertThat(idAttributeField, nullValue());
543+
assertThat(idAttributeField, notNullValue());
544544
}
545545
}

0 commit comments

Comments
 (0)