Skip to content

Commit b2d6344

Browse files
committed
Cater for author being a Long or Array ... in some cases we are getting an array. Strange but true. This now caters for both
1 parent 7a9dfee commit b2d6344

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.afrozaar.wordpress</groupId>
55
<artifactId>wp-api-v2-client-java</artifactId>
6-
<version>4.10.0</version>
6+
<version>4.11.0</version>
77

88
<packaging>jar</packaging>
99

src/main/java/com/afrozaar/wordpress/wpapi/v2/model/Post.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public class Post {
4545

4646
@JsonProperty("author")
47-
private Long author;
47+
private List<Long> author = new ArrayList<>();
4848
@JsonProperty("content")
4949
private Content content;
5050
@JsonProperty("status")
@@ -101,13 +101,11 @@ public void setCategoryIds(List<Long> categoryIds) {
101101
this.categoryIds = categoryIds;
102102
}
103103

104-
@JsonProperty("author")
105104
public Long getAuthor() {
106-
return author;
105+
return author.size() > 0 ? author.get(0) : null;
107106
}
108107

109-
@JsonProperty("author")
110-
public void setAuthor(Long author) {
108+
public void setAuthor(List<Long> author) {
111109
this.author = author;
112110
}
113111

src/main/java/com/afrozaar/wordpress/wpapi/v2/model/builder/PostBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.afrozaar.wordpress.wpapi.v2.model.Title;
1111

1212
import java.util.Arrays;
13+
import java.util.Collections;
1314
import java.util.List;
1415

1516
/**
@@ -183,7 +184,7 @@ public PostBuilder but() {
183184

184185
public Post build() {
185186
Post post = new Post();
186-
post.setAuthor(author);
187+
post.setAuthor(Collections.singletonList(author));
187188
post.setId(id);
188189
post.setTitle(title);
189190
post.setLinks(Links);

src/main/java/com/afrozaar/wordpress/wpapi/v2/response/CustomRenderableParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
import org.springframework.http.HttpStatus;
99
import org.springframework.http.ResponseEntity;
10+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
1011
import org.springframework.web.client.HttpClientErrorException;
1112

13+
import com.fasterxml.jackson.databind.DeserializationFeature;
1214
import com.fasterxml.jackson.databind.JsonNode;
1315
import com.fasterxml.jackson.databind.ObjectMapper;
1416
import com.fasterxml.jackson.databind.node.ObjectNode;
15-
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
1819

@@ -41,7 +42,7 @@ public final class CustomRenderableParser {
4142
private static final Logger LOG = LoggerFactory.getLogger(CustomRenderableParser.class);
4243
public static final String FIELD_PREVIOUS = "previous";
4344
public static final String FIELD_DELETED = "deleted";
44-
private static ObjectMapper objectMapper = new ObjectMapper();
45+
private static ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().featuresToEnable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY).build();
4546
private static final Set<String> modifiableFields = new HashSet<>(Arrays.asList("description", "caption"));
4647
private static final String RENDERED = "rendered";
4748
private static final String RAW = "raw";

0 commit comments

Comments
 (0)