Sending JSON with enum data types - java

I am trying to send a json with a data type that is a enum according to the ebay documantion here:
http://developer.ebay.com/devzone/rest/api-ref/inventory/types/OperatingHours.html
The field in question is the dayOfWeekEnum, which I tried sending in my JSON several ways:
{"dayOfWeekEnum": "FRIDAY"}
{"dayOfWeekEnum": 0}
{"dayOfWeekEnum": {"dayOfWeekEnum": "FRIDAY"}}
And none of them didn't work. I alwyas get the message saying it could not serialize the field dayOfWeekEnum:
[{"errorId"=>2004, "domain"=>"ACCESS", "category"=>"REQUEST", "message"=>"Invalid request", "longMessage"=>"The request has errors. For help, see the documentation for this API.", "parameters"=>[{"name"=>"reason", "value"=>"Could not serialize field [operatingHours.dayOfWeekEnum]"}]}]
I am assuming ebay runs a Java api, so how should I send my JSON enum info properly?

I know from experience that eBay's documentation can be wrong when it comes to the names of fields. Have you tried passing dayOfWeek instead of dayOfWeekEnum?

Related

how to create the data model for this { "words":[3,4,5] } json in kotlin

I was trying to write a data model to send a JSON to the API and delete some fields
the JSON should contain the id of some words and it should look exactly like this :
{
"words":[3,4,5]
}
as I know and also as the https://jsonformatter.org/ said the data class should be something like the following piece of code:
data class words(var id: List<Int>)
but the problem is when I pass the data to it and toast it to see if it's a valid JSON request for the server the output will be this :
words(id=[1,2,4,5])
and it's not what it should be.
as I said I need this :
{
"words":[3,4,5]
}
I think the following should work.
data class AnyNameYouWant(val words: List<Int>)
I think the name of the data class really doesn't matter as it would finally represent the { } object syntax of json.
Looking in the comments, I think it's better to use some logging library like Timber. If you are using Retrofit then use can also use HttpLoggingInterceptor and set the level to Body that will print the body of the response in the logcat.

Handling inconsistent data types in REST results (json) in Java

I'm new, and attempting to work with the Rest API on setlist.fm from Android Studio, but am having some issues when fitting my GET request results into my Java data model.
Particularly, I have modeled "sets" ("set" refers to a set played at a concert) as a Java class. But commonly, I get results back from my HTTP requests that have "set" as an empty string or even an array.
I'll use this following GET request for all Radiohead setlists as an example:
http://api.setlist.fm/rest/0.1/artist/a74b1b7f-71a5-4011-9441-d0b5e4122711/setlists.json
Notice how, for the most part, "sets" is an object. But in some instances, it is a String. In other instances it is an array.
My Android Studio is giving me the following error when I try to parse the json with Gson into my data model using the following line of code:
gson.fromJson(result.toString(),Response.class);
It appears to be failing on an instance where "sets" is shown an empty string rather than an object:
Expected BEGIN_OBJECT but was STRING at line 1 column 942 path $.setlists.setlist[0].sets
Does anyone have advice on how to handle this type of thing? I've noticed it with all artists I've looked up so far.
Thanks!
Assuming Response is a class you wrote containing the main fields of the json and that at some point in it you have:
#SerializedName("setlist")
private List<MyItem> setlist;
I also assume your MyItem class contains the field:
#SerializedName("sets")
private List<MySet> sets;
if you let Gson parse it it will fail when it found a string instead of a list (-> array) of MySet object.
But you can write a custom TypeAdapter for your MyItem.
There's plenty of documentation about how to write a Gson TypeAdapter, look for it.
Use instanceOf operator to determine the type and cast accordingly.
JSONObject response=new JSONObject(res);
if(res.get("key") instanceOf JSONObject)
{
// code for JSONObject
}
else if(res.get("key") instanceOf JSONArray)
{
// code for JSONOArray
}
And so on

how to solve Json data in eclipse console,can any one solve this

when i am Running tomcat, i am getting Json data in eclipse console,..
i used and already asked this [here]JSON Responce data Getting at Console i used Java,Eclipse,Tomcat
main problem i am getting Json data in eclipse console,..
but again same problem,..
I want it at localhost:8080/myclassname/myservices/controls
like [here] http://javatechig.com/api/get_category_posts/?dev=1&slug=android
as this above way i want Json data,.. in my url but i am getting error,..
i used Json, java,eclipse,tomcat,..
I got answer when i need to print this in web service. I changed with Returl null to return obj.toString(). Now I am getting data at web page instead of console.

Exception while creating custom object using Salesforce CRUD Metadata API

I am getting the following exception when I try to create a Custom Object in Salesforce, using CRUD Matadata API.
com.sforce.ws.SoapFaultException: Must specify a {http://www.w3.org/2001/XMLSchema-instance}
type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element
at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:205)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:149)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
at com.sforce.soap.metadata.MetadataConnection.create(MetadataConnection.java:273)
at com.sfo.service.SalesforceObjectBootstrap.createCustomObject(SalesforceObjectBootstrap.java:226)
I am using the code from this link, The only thing that I changed were the name of the Custom Object
http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_calls_intro.htm
The exception occurs at this step
AsyncResult[] asyncResults = metadataConnection.create(new CustomObject[]{customObject});
The Custom object just before invoking the create method above has the following parameter values.
[CustomObject [Metadata fullName='lead_5273_custom_reg__c'
]
actionOverrides='{[0]}'
articleTypeChannelDisplay='null'
businessProcesses='{[0]}'
customHelp='hey there help me'
customHelpPage='null'
customSettingsType='null'
customSettingsVisibility='null'
deploymentStatus='Deployed'
deprecated='false'
description='Created from backend Webcast API : Lead 5273 Custom Reg'
enableActivities='false'
enableDivisions='false'
enableEnhancedLookup='false'
enableFeeds='false'
enableHistory='false'
enableReports='false'
fieldSets='{[0]}'
fields='{[0]}'
gender='null'
household='false'
label='Lead 5273 Custom Reg'
listViews='{[0]}'
nameField='[CustomField [Metadata fullName='lead_5273_custom_reg__c'
]
caseSensitive='false'
customDataType='null'
defaultValue='null'
deleteConstraint='null'
deprecated='false'
description='field name for a metadata custom object'
displayFormat='null'
escapeMarkup='false'
externalDeveloperName='null'
externalId='false'
formula='null'
formulaTreatBlanksAs='null'
inlineHelpText='null'
label='Lead 5273 Custom Reg'
length='0'
maskChar='null'
maskType='null'
picklist='null'
populateExistingRows='false'
precision='0'
referenceTo='null'
relationshipLabel='null'
relationshipName='null'
relationshipOrder='0'
reparentableMasterDetail='false'
required='false'
restrictedAdminField='false'
scale='0'
startingNumber='0'
stripMarkup='false'
summarizedField='null'
summaryFilterItems='{[0]}'
summaryForeignKey='null'
summaryOperation='null'
trackFeedHistory='false'
trackHistory='false'
type='Text'
unique='false'
visibleLines='0'
writeRequiresMasterRead='false'
]
'
namedFilters='{[0]}'
pluralLabel='Lead 5273 Custom Regs'
recordTypeTrackFeedHistory='false'
recordTypeTrackHistory='false'
recordTypes='{[0]}'
searchLayouts='null'
sharingModel='ReadWrite'
sharingReasons='{[0]}'
sharingRecalculations='{[0]}'
startsWith='null'
validationRules='{[0]}'
webLinks='{[0]}'
]
I used the method mentioned here to generate the WSDL files and its java skeleton.
http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_quickstart.htm#topic-title-sample-code
My code exactly matches the example provided above. I simply copy pasted the whole thing.
I found this link, which mentioned the same exception. But this link is relating to creating a Folder.
http://boards.developerforce.com/t5/Java-Development/Metadata-API-errors-Must-specify-a-type-attribute-value-for-the/td-p/175253
Please let me know how to solve this problem.
I've not played with this myself, but from the looks of the exception, the MetaData block here:
[CustomObject [Metadata fullName='lead_5273_custom_reg__c']
needs to contain the object type, which I'm assuming in this case is CustomObject__c (all custom objects have the __c suffix), so maybe try the following:
[CustomObject [Metadata fullName='lead_5273_custom_reg__c' type='CustomObject__c']
Unless of course, fullname is actually the object name, which could be a possibility.

Disqus API for getting the list of posts from the forum

I am using the Disqus API for getting the list of posts for a particular forum.
The url that i am using to get the posts is -
'http://disqus.com/api/3.0/forums/listPosts.json'
In the disqus api docs they have provided the parameters that can be passed to the above url. Out of which 'since' is one, which can be used to get all the posts after the specified date.
In the api docs they have mentioned that we can use Unix timestamp (or ISO datetime standard) as the value for the 'since' param.
I have tried with both types of values but it gives me all the posts i.e. the since constraint is never applied.
Can you please help me out to know how to use 'since' param.
Thanks !!
yes the order param is bydefault set to 'desc'...you can get more info on this link: http://disqus.com/api/docs/forums/listPosts/
I use mootools, can you show me javascript code for that ajax request?
My js is:
new Request.JSONP({
url :"https://disqus.com/api/3.0/threads/list.jsonp?api_key=9ldXlWCWlsyjMI3qvf03Y8OQCNxvAMklHkrNVcpBKm220XJHXsU0QDdr0TCLM1kz",//&forum=colourasexperience&thread=ident:cae52020",
callbackKey: 'showMyInfoes',
onSuccess: function(jdata){
//console.log(jdata);
}
}).send();
Thanks

Categories