[wp-trac] [WordPress Trac] #54484: REST API returns (empty) array for Post Meta but Schema has type object

WordPress Trac noreply at wordpress.org
Sun Nov 21 18:35:55 UTC 2021


#54484: REST API returns (empty) array for Post Meta but Schema has type object
--------------------------+-----------------------------
 Reporter:  dtrunk90      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  5.8.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When checking http://localhost/wp-json/wp/v2/posts (fresh setup) the meta
 field is an empty array:

 {{{
 [{"id":1,...,"meta":[],...}]
 }}}

 But the schema (localhost/wp-json/wp/v2/posts?_method=OPTIONS) has type
 definition object:

 {{{
 {
    ...,
    "schema":{
       "$schema":"http:\/\/json-schema.org\/draft-04\/schema#",
       "title":"post",
       "type":"object",
       "properties":{
          ...,
          "meta":{
             "description":"Metafelder.",
             "type":"object",
             "context":[
                "view",
                "edit"
             ],
             "properties":[

             ]
          },
          ...
       },
       ...
    },
    ...
 }
 }}}

 Either the schema is wrong and should be array or REST API should not
 return an empty array

 I'm downloading the schema from my local WordPress instance in order to
 create POJOs and using those with Springs WebClient which results in the
 following error:

 {{{
 Error: JSON decoding error: Cannot deserialize value of type
 `com.acme.api.wp.Meta` from Array value (token `JsonToken.START_ARRAY`);
 nested exception is
 com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
 deserialize value of type `com.acme.api.wp.Meta` from Array value (token
 `JsonToken.START_ARRAY`)
  at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain:
 com.acme.api.wp.Posts["meta"])
 }}}

 Manually changing type from object to array fixes it. But I'm not sure if
 the schema is wrong or the REST API is returning invalid data.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54484>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list