如何解决如何将实现IEnumerable的复杂类型传递给请求正文中的C#Web API Post方法
我正在尝试将JSON传递给请求正文中的C#Web API Post方法。将JSON反序列化为复杂类型(UserActionLogger)可以正常工作,直到该类尚未实现IEnumerable为止,其中T = UserActionLog,复杂类型。
工作正常:
@Bean
JwtDecoder jwtDecoder() {
JWSKeySelector<SecurityContext> jwsKeySelector;
try {
URL jwksUrl = new URL(authConfiguration.getJwksUrl());
JWKSetCache jwkSetCache = new DefaultJWKSetCache(authConfiguration.getJwksCacheTtlMins(),TimeUnit.MINUTES);
RemoteJWKSet<SecurityContext> jwkSet = new RemoteJWKSet<>(jwksUrl,null,jwkSetCache);
jwsKeySelector = JWSAlgorithmFamilyJWSKeySelector.fromJWKSource(jwkSet);
} catch (KeySourceException | MalformedURLException e) {
throw new InvalidConfigurationException(e.getMessage());
}
DefaultJWTProcessor<SecurityContext> jwtProcessor = new DefaultJWTProcessor<>();
jwtProcessor.setJWSKeySelector(jwsKeySelector);
NimbusJwtDecoder jwtDecoder = new NimbusJwtDecoder(jwtProcessor);
OAuth2TokenValidator<Jwt> audienceValidator = new AudienceValidator(authConfiguration.getAudience());
OAuth2TokenValidator<Jwt> withIssuer = JwtValidators.createDefaultWithIssuer(authConfiguration.getIssuer());
OAuth2TokenValidator<Jwt> withAudience = new DelegatingOAuth2TokenValidator<>(withIssuer,audienceValidator);
jwtDecoder.setJwtValidator(withAudience);
return jwtDecoder;
}
但是一旦实现IEnumerable(IEnumerable),反序列化将停止工作。反序列化的值变为空
课程:
public class UserActionLogger
{
[JsonProperty("userActionLogs")]
public List<UserActionLog> UserActionLogs { get; set; }
}
发布操作方法:-
public class UserActionLogger : IEnumerable<UserActionLog>
{
private List<UserActionLog> _userActionLogs;
[JsonProperty("userActionLogs")]
public List<UserActionLog> userActionLogs {
get
{
return _userActionLogs;
}
set
{
_userActionLogs = value;
}
}
public UserActionLog this[int index]
{
get { return _userActionLogs[index]; }
set { _userActionLogs.Insert(index,value); }
}
public IEnumerator<UserActionLog> GetEnumerator()
{
return ((IEnumerable<UserActionLog>)_userActionLogs).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
public class UserActionLog
{
[JsonProperty("eventType")]
public string EventType { get; set; }
[JsonProperty("eventSubType")]
public string EventSubType { get; set; }
//other properties removed
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。