1

Closed

Required property 'x' not found in JSON. Path '', line x, position x.

description

Hi,

I'm not sure whether this is a bug that was introduced in 4.5.9 or that was fixed in 4.5.9.

Basically we've got a Web API that our MVC Application post's to, both with the same version of NewtonsoftJSON. This was version 4.5.7 but we've recently done an upgrade to 4.5.11.

At it's core we've got a Enum validator that extends the Required validator, we've had this on an Enum that goes from 0-3 that's passed between our MVC application and our Web Api application this has been working fine but with update 4.5.9 it now fails on the Required validator only for the Enum value that's 0.

What happens is this now throws an exception during Validating:
Required property 'x' not found in JSON. Path '', line x, position x.

Is this intentional?

Some Technical Snippets.

On the WCF Web Service we've got a Controller/Action that looks like this:
public HttpResponseMessage Post(PublishRequest) { 
    ... 
}

The PublishRequest looks like
public class PublishRequest {

    [EnumRequired(ErrorMessage="Blah")]
    public StructureEnum SalaryStructureEnum { get; set; }

}
Our StructureEnum looks like:
public enum StructureEnum {
       Annual = 0,
       AnnualAndCommission = 1,
       CommissionOnly = 2,
       HourlyRate = 3
}
and our Enum Required attribute is:
public class EnumRequiredAttribute : RequiredAttribute {
    public override bool IsValid(object value) {
        return Enum.IsDefined(value.GetType(), value);
    }
}
Closed Jan 30, 2013 at 11:18 AM by JamesNK

comments

JamesNK wrote Jan 22, 2013 at 8:55 AM

Sorry I don't know how Web API uses Json.NET for RequiredAttribute. If you attach a simple example I could take a look. You could also ask the Web API guys about it.

michaeldowling wrote Jan 24, 2013 at 12:05 AM

Alright I'll get a little solution to illustrate the issue.

The exception seems to be thrown from the Newtonsoft library