juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: How to get a class to return standard JSON as the default
Date Fri, 09 Feb 2018 16:25:41 GMT
On Fri, Feb 9, 2018 at 7:51 AM, James Bognar <jamesbognar@gmail.com> wrote:

> Hi Gary,
>
> Try using a default request header:
>
> @RestResource(
>
> defaultRequestHeaders= {
>
> "Accept: application/json"
>
> },
>
> )
>
> I'll take a closer look at how "no" Accept header is handled.  I think it
> depends on what tool you're using.  Poster for example sends "Accept: */*"
> if you don't specify a value, and that might return a somewhat-random
> result.
>

That does not work for me sadly. Here a snipet of my service that extends
ResourceGroup. I am using Postman 5.5.2. I am getting back an HTML table
for my service.

@RestResource(
// @formatter:off
path="/",
title="Access & Connectivity Agent Microservice",
description="Administration",
        defaultRequestHeaders= {
                "Accept: application/json"
},
htmldoc=@HtmlDoc(
                head={
                        "<link rel='apple-touch-icon' sizes='57x57'
href='$U{servlet:/htdocs/images/apple-icon-57x57.png}'/>",
                        "<link rel='apple-touch-icon' sizes='60x60'
href='$U{servlet:/htdocs/images/apple-icon-60x60.png}'/>",
                        "<link rel='apple-touch-icon' sizes='72x72'
href='$U{servlet:/htdocs/images/apple-icon-72x72.png}'/>",
                        "<link rel='apple-touch-icon' sizes='76x76'
href='$U{servlet:/htdocs/images/apple-icon-76x76.png}'/>",
                        "<link rel='apple-touch-icon' sizes='114x114'
href='$U{servlet:/htdocs/images/apple-icon-114x114.png}'/>",
                        "<link rel='apple-touch-icon' sizes='120x120'
href='$U{servlet:/htdocs/images/apple-icon-120x120.png}'/>",
                        "<link rel='apple-touch-icon' sizes='144x144'
href='$U{servlet:/htdocs/images/apple-icon-144x144.png}'/>",
                        "<link rel='apple-touch-icon' sizes='152x152'
href='$U{servlet:/htdocs/images/apple-icon-152x152.png}'/>",
                        "<link rel='apple-touch-icon' sizes='180x180'
href='$U{servlet:/htdocs/images/apple-icon-180x180.png}'/>",
                        "<link rel='icon' type='image/png' sizes='192x192'
href='$U{servlet:/htdocs/images/android-icon-192x192.png}'/>",
                        "<link rel='icon' type='image/png' sizes='32x32'
href='$U{servlet:/htdocs/images/favicon-32x32.png}'/>",
                        "<link rel='icon' type='image/png' sizes='96x96'
href='$U{servlet:/htdocs/images/favicon-96x96.png}'/>",
                        "<link rel='icon' type='image/png' sizes='16x16'
href='$U{servlet:/htdocs/images/favicon-16x16.png}'/>",
                        "<link rel='manifest'
href='$U{servlet:/htdocs/images/manifest.json}'/>",
                        "<meta name='msapplication-TileColor'
content='#ffffff'/>",
                        "<meta name='msapplication-TileImage'
content='$U{servlet:/htdocs/images/ms-icon-144x144.png}'/>",
                        "<meta name='theme-color' content='#ffffff'/>"
                },
                header={
                "<h1>$R{servletTitle}</h1>",
                "<h2>$R{methodSummary,$R{servletDescription}}</h2>",
                "<a href='https://www.rocketsoftware.com'><img
src='$U{servlet:/htdocs/images/ram.png}'
style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/></a>"
        },
widgets={
ContentTypeMenuItem.class,
StyleMenuItem.class,
},
navlinks={
"options: servlet:/?method=OPTIONS",
        "$W{ContentTypeMenuItem}"
}
),
children={
ConfigResource.class,
LogsResource.class
}
// @formatter:on
)
public class AdminRootResources extends ResourceGroup {
...
    @RestMethod(name = GET, path = PATH_STATUS, summary = "Status",
description = "Gets status for the running system.")
    public Map<String, Object> getStatus() {
...

Thank you,
Gary


>
> On Thu, Feb 8, 2018 at 9:11 PM, Gary Gregory <garydgregory@gmail.com>
> wrote:
>
>> Hi All:
>>
>> I want to return _standard_ JSON (see json.org) when no Accept header is
>> sent to my @RestResource class. I cannot seem to get that to work no matter
>> what. I get Juneau's non-standard single quote JSON.
>>
>> Standard JSON uses double quotes, not single quotes.
>>
>> If I specify 'application/json' in the Accept, then I do get standard
>> JSON.
>>
>> I cannot get this to work no matter what I try in my class's
>> @RestResource's serializer attribute.
>>
>> I also want to support the normal set of serializers so users can specify
>> any Accept header value Juneau supports.
>>
>> Thank you,
>> Gary
>>
>
>

Mime
View raw message