java.lang.NoSuchFieldError: USE_DEFAULTS thrown while validating json schema through json schema validator - json

I am new to RestAPI testing. I am trying to use Jsonschemavalidor. I added the jar file and all the dependencies. Still I get following error. Can anyone give solution to the problem.
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:205)
at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:45)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:543)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:460)
at com.github.fge.jackson.JacksonUtils.newMapper(JacksonUtils.java:155)
at com.github.fge.jackson.JacksonUtils.<clinit>(JacksonUtils.java:55)
at com.github.fge.jackson.JsonNodeReader.<init>(JsonNodeReader.java:82)
at com.github.fge.jackson.JsonLoader.<clinit>(JsonLoader.java:50)
at com.jayway.restassured.module.jsv.JsonSchemaValidator$4.createJsonNodeInstance(JsonSchemaValidator.java:164)
at com.jayway.restassured.module.jsv.JsonSchemaValidator$4.createJsonNodeInstance(JsonSchemaValidator.java:161)
at com.jayway.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.create(JsonSchemaValidator.java:254)
at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema(JsonSchemaValidator.java:161)
at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath(JsonSchemaValidator.java:117)
at com.nasdaq.api.GenericLib.validateJsonSchema(GenericLib.java:441)

Did you add the latest version of jackson-annotations? The USE_DEFAULTS enum constant was added in 2.6:

Related

custom exception message in spring cloud function deployed in aws-lambda

I have a java project written using spring-cloud-function and deployed in aws-lambda.
I am trying to return a custom exception with some fields in the exception message body, something like"
{
reason: <exception reason>
code: <error code>
<some other fields>
}
#ExceptionHandler, that is generally used in spring boot doesn't seem to work here.
I can return the exception in the required format by creating a class for building the exception message in required format but in that case the error code will always be 200 since it will not be an exception object per se. Instead it will be my custom error object.
Is there a way I can set this up so that the above required format of exception object is returned and correct error code can be returned too?
Thanks in advance
First, the exception has nothing to do with Spring Boot. It's part of spring-web, so yes it would not work here since s-c-function is a general purpose framework, where the same function could be deployed and triggered via web, streaming, aws-lambda etc. .
Now, yes we had a problem returning JSON error (as you show) or object that represents the same, but that was fixed. So please update s-c-function to 3.2.3.

"Error Deserializing JSON Credential Data" gcp auth file c#

Following on from this question, I'd like to open a related one to verify an answer.
Originally my code looked like
string path2key = "C:/Users/me/Downloads/project-id-1-letters.json";
string jsonString = File.ReadAllText(path2key);
Console.WriteLine(jsonString); // this works and prints correctly
// I presume I'm passing json as a string???
var credential = GoogleCredential.FromJson(jsonString);
but I was getting the following error
System.InvalidOperationException: 'Error deserializing JSON credential data.'
FileNotFoundException: Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
I'm using netframework 4.5, meaning I'm somewhat limited in updating packages to the latest and greatest.
The other answer is correct. I was about to post the same answer but #serge beat me to it.
The class GoogleCredentials has a member FromJson. That member takes a string argument. In your code, you were trying to pass an object.
For the error in your comment to the answer:
FileNotFoundException: Could not load file or assembly 'System.Security.Permissions
That error can be corrected by using nuget package manager and adding System.Security.Permissions or via the CLI:
dotnet add package System.Security.Permissions

What is the cause of FluentValidation Method Not Found exception?

I've got a Domain Driven Design solution and for some reason, I'm getting this exception at RunTime when the API call is made through GateWay:
One or more errors occurred. (Method not found: 'Void FluentValidation.AbstractValidator`1.When(System.Func`2<!0,Boolean>, System.Action)'.)
The error occurs as below:
I have solution like this:
The main 4 project I'm focusing on right now are:
Core.Model
Account.Api
Service.Api.Gateway
Web.ClientSite
Web.ClientSite makes request to Service.Api.Gateway which then calls Account.Api.
Note that Core.Model is referenced everywhere
VERY IMPORTANT: If I remove the reference of FluentValidation from Core.Model, the exception disappears.
I'm hoping these information is enough. Why do you think I'm getting this exception and how can I eliminate.
Looks like some of libs (ocelot) are incompatible with new changes in FluentValidation 8.1.2. Try to downgrade to FluentValidation before 8.1.2. Hope it helps
I got similar exception:
System.MissingMethodException : Method not found:
'FluentValidation.AssemblyScanner
FluentValidation.AssemblyScanner.FindValidatorsInAssembly(System.Reflection.Assembly)'
In my case I needed to upgrade the ediatR.Extensions.Microsoft.DependencyInjection and MediatR.Extensions.FluentValidation.AspNetCore packages as well to fix the issue.

How to set the read and write providers for JSON using JAX-RS in Apache Tomee plus

I can return simple text from my Pojo but it fails when I changed to return JSON. I have the correct annotations for produces and consumes in my methods and I checked that the content negotation between Jquery and the server is correct.
It seems to be that the conversion to JSON just fails. I copied the Jackson jars in webapps/tomee/lib. I also tried the lib folder of my application.
The error message when doing a GET:
No message body writer has been found for response class <myClass>
This error is fired by the JAXRSOut Intercepter class
The error when doing a Post is:
No message body reader has been found for request class <myClass>
This error is fired by the JAXRSUtils class
Thanks
I made this work by listing the JAX-RS providers in conf/system.properties file of TomEE. Then I added the jars to TomEE's lib folder. The documentation in the website states that one should drop the jars on webapp/tomee/lib, but that did not work for me.
conf/system.properties
openejb.cxf.jax-rs.providers = org.codehaus.jackson.jaxrs.JacksonJsonProvider, org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
Jars I dropped:
jackson-mapper-asl-1.9.9.jar
jackson-core-asl-1.9.9.jar
jackson-jaxrs-1.9.9
If you use jersey you could try Genson library http://code.google.com/p/genson/.
Latest version 0.92 provides automatic detection of json support in jax-rs web services with jersey.
You should only have to drop the jar and voila! :)

Unable to parse JSON error using Twitterizer TwitterStatus.Show method

Running this code:
var statusResponse = TwitterStatus.Show(tweet.Id);
gives an error message: Unable to parse JSON in the statusResponse object and the ResponseObject comes back as null.
Not sure how to fix this. Any ideas?
I run into the same issue today. It seems that you reference a newer version of Newtonsoft.Json in your project (or maybe an other NuGet package included it).
The problem can be fixed by using the Newtonsoft.Json 4.0.5.0 library that is shipped with the Twitterizer project. It needs to be that exact version.