0

Having problems with FOSRestBundle custom routes, i followed the below link but that didn't solve my problem. My problem is that when i don't specify a format it defaults to XML not JSON.

How to specify default format for FOS\RestBundle to json?

Config.yml

fos_rest:
routing_loader:
    default_format: json
    include_format: true
param_fetcher_listener: force
body_listener: true
allowed_methods_listener: true
view:
    view_response_listener: 'force'
    formats:
        json: true
        xml: true
format_listener:
    rules:
        - { path: '^/api', fallback_format: json, priorities: ['json', 'xml'], prefer_extension: true }

routing.yml

get_forms:
pattern:  /api/v4/forms.{_format}
defaults: { _controller: NmpoloRestBundle:Form:cget, _format: ~ }

Does anyone know why my default goes to XML when i hit: www.test.com/api/v4/forms

its XML format not JSON. Any help would be appreciated. thx

Community
  • 1
  • 1
Hard Fitness
  • 452
  • 3
  • 9
  • 24

1 Answers1

1

I managed to default to json by placing the following in app/config/config.yml

fos_rest:
    //...
    routing_loader:
        default_format: json

My complete config was

fos_rest:
    serializer:
        serialize_null: true
    routing_loader:
        default_format: json
    format_listener: true
    view:
        view_response_listener: 'force'

No extra configuration in routing files was necessary

Alex
  • 1,565
  • 2
  • 9
  • 13
  • i was able to just change format_listener: true and that solved it all but yours is right as well, just shows me all the NULL values as well. What is that serializer_null? – Hard Fitness Sep 09 '14 at 18:24
  • It believe it means the API will return values even when they are null, which was required for the particular project – Alex Sep 09 '14 at 18:25
  • ok makes perfect sense, that is why i could see all the NULL values as well on my JSON array. – Hard Fitness Sep 09 '14 at 18:27
  • Great. Good luck with your project – Alex Sep 09 '14 at 18:28