本文整理汇总了Java中javax.validation.Payload类的典型用法代码示例。如果您正苦于以下问题:Java Payload类的具体用法?Java Payload怎么用?Java Payload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Payload类属于javax.validation包,在下文中一共展示了Payload类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConstraintDescriptorImpl
import javax.validation.Payload; //导入依赖的package包/类
protected ConstraintDescriptorImpl(final T annotation, final Set<Class<?>> groups,
final Set<Class<? extends Payload>> payload,
final List<Class<? extends ConstraintValidator<T, ?>>> constraintValidatorClasses,
final Map<String, Object> attributes, final Set<ConstraintDescriptor<?>> composingConstraints,
final boolean reportAsSingleViolation, final ElementType elementType,
final ConstraintOrigin definedOn) {
super();
this.annotation = annotation;
this.groups = groups;
this.payload = payload;
this.constraintValidatorClasses = constraintValidatorClasses;
this.attributes = attributes;
this.composingConstraints = composingConstraints;
this.reportAsSingleViolation = reportAsSingleViolation;
this.elementType = elementType;
this.definedOn = definedOn;
}
示例2: buildTemplateConstraint
import javax.validation.Payload; //导入依赖的package包/类
private JDefinedClass buildTemplateConstraint(String name) {
try {
JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
tplConstraint.annotate(Documented.class);
tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
// Using direct as I don't know how to build default { } with code model
tplConstraint.direct("\n" + " Class<?>[] groups() default {};\n" + " String message() default \"Invalid value\";\n" + " Class<? extends Payload>[] payload() default {};\n");
// Hack to force the import of javax.validation.Payload
tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
return tplConstraint;
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Tried to create an already existing class: " + name, e);
}
}
示例3: getConstraintSeverity
import javax.validation.Payload; //导入依赖的package包/类
/**
* (non-Javadoc)
*
* @see com.github.nest.arcteryx.meta.beans.IConstraintViolation#getConstraintSeverity()
*/
@SuppressWarnings("unchecked")
@Override
public ConstraintSeverity getConstraintSeverity() {
Set<Class<? extends Payload>> payloads = this.getViolation().getConstraintDescriptor().getPayload();
if (payloads == null || payloads.size() == 0) {
return ConstraintSeverity.defaultSeverity();
} else {
// get first one
Class<? extends Payload> payloadClass = payloads.iterator().next();
if (HibernateSeverity.INFO.class == payloadClass) {
return ConstraintSeverity.INFO;
} else if (HibernateSeverity.WARN.class == payloadClass) {
return ConstraintSeverity.WARN;
} else if (HibernateSeverity.ERROR.class == payloadClass) {
return ConstraintSeverity.ERROR;
} else if (HibernateSeverity.FATAL.class == payloadClass) {
return ConstraintSeverity.FATAL;
} else {
return ConstraintSeverity.defaultSeverity();
}
}
}
示例4: errorMessage
import javax.validation.Payload; //导入依赖的package包/类
private String errorMessage(ConstraintViolation<?> error) {
Set<Class<? extends Payload>> payload = error.getConstraintDescriptor().getPayload();
if (payload.contains(NoLogging.class)) {
return error.getPropertyPath().toString() + ", " + error.getMessage();
} else {
return error.getPropertyPath().toString() + ", " + error.getMessage() + ", was: " + error.getInvalidValue();
}
}
示例5: getMessage
import javax.validation.Payload; //导入依赖的package包/类
/**
* Calculate a localized string message for a constraint violation.
* <p>
* If a labeled payload is present, the label of the payload is used as
* template. Although not required, you are encouraged to use
* {@link ValidationMessage} as base class for such payloads. If no labeled
* payload is present and the message has the form "{......}", the string
* without the brackets is used as key and the corresponding resource string
* is used as template. Otherwise, the message is used directly as template.
*
* <p>
* When the template is determined, it is used to create a
* {@link PatternString} . The arguments are the standard validation
* arguments (all attributes of the constraint annotation) plus
* "invalidValue" containing the value which has been validated.
*
* <p>
* finally the PatternString is resolved and returned as message.
*
*/
public LString getMessage(ConstraintViolation<?> violation) {
// arguments for the message
Map<String, Object> args = new HashMap<>();
args.putAll(violation.getConstraintDescriptor().getAttributes());
args.put("invalidValue", violation.getInvalidValue());
// check for labeled payload
{
Optional<TranslatedString> pattern = violation.getConstraintDescriptor().getPayload().stream()
.filter(Payload.class::isAssignableFrom).map(x -> labelUtil.type(x).tryLabel())
.filter(x -> x.isPresent()).map(x -> x.get()).findFirst();
if (pattern.isPresent())
// we found a labeled payload. Use payload label as pattern
return new PatternString(patternStringResolver, pattern.get(), args);
}
// check for resource key reference
String messageTemplate = violation.getMessageTemplate();
if (messageTemplate.startsWith("{") && messageTemplate.endsWith("}")) {
return new PatternString(patternStringResolver, new TranslatedString(translatedStringResolver,
messageTemplate.substring(1, messageTemplate.length() - 1)), args);
}
// fallback: just use the string as is as pattern
return new PatternString(patternStringResolver, LString.of(messageTemplate), args);
}
示例6: ConstraintDescriptorImpl
import javax.validation.Payload; //导入依赖的package包/类
protected ConstraintDescriptorImpl(final T pannotation, final Set<Class<?>> pgroups,
final Set<Class<? extends Payload>> ppayload,
final List<Class<? extends ConstraintValidator<T, ?>>> pconstraintValidatorClasses,
final Map<String, Object> pattributes,
final Set<ConstraintDescriptor<?>> pcomposingConstraints,
final boolean preportAsSingleViolation, final ElementType pelementType,
final ConstraintOrigin pdefinedOn) {
super(pannotation, pgroups, ppayload, pconstraintValidatorClasses, pattributes,
pcomposingConstraints, preportAsSingleViolation, pelementType, pdefinedOn);
}
示例7: convertSeverity
import javax.validation.Payload; //导入依赖的package包/类
/**
* convert severity
*
* @param constraint
* @return
*/
protected Class<? extends Payload> convertSeverity(C constraint) {
ConstraintSeverity severity = constraint.getSeverity();
if (ConstraintSeverity.INFO.equals(severity)) {
return HibernateSeverity.INFO.class;
} else if (ConstraintSeverity.WARN.equals(severity)) {
return HibernateSeverity.WARN.class;
} else if (ConstraintSeverity.ERROR.equals(severity)) {
return HibernateSeverity.ERROR.class;
} else if (ConstraintSeverity.FATAL.equals(severity)) {
return HibernateSeverity.FATAL.class;
} else {
return HibernateSeverity.INFO.class;
}
}
示例8: getPayload
import javax.validation.Payload; //导入依赖的package包/类
@Override
public Set<Class<? extends Payload>> getPayload() {
throw new UnsupportedOperationException();
}
示例9: payload
import javax.validation.Payload; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Class<? extends Payload>[] payload() {
return new Class[0];
}
示例10: payload
import javax.validation.Payload; //导入依赖的package包/类
@Override
public Class<? extends Payload>[] payload()
{
throw new UnsupportedOperationException();
}
示例11: getConstraintDescriptor
import javax.validation.Payload; //导入依赖的package包/类
@Required
@Override
public ConstraintDescriptor<?> getConstraintDescriptor() {
String methodName = "getConstraintDescriptor";
Method method;
try {
method = MockConstraintViolation.class.getMethod(methodName, new Class<?>[] {});
} catch (NoSuchMethodException | SecurityException e) {
throw new IllegalStateException("Failed to get the method: " + methodName, e);
}
Required annotation = method.getAnnotation(Required.class);
return new ConstraintDescriptor<Annotation>() {
@Override
public Annotation getAnnotation() {
return annotation;
}
@Override
public String getMessageTemplate() {
return null;
}
@Override
public Set<Class<?>> getGroups() {
return DfCollectionUtil.newHashSet(ClientError.class);
}
@Override
public Set<Class<? extends Payload>> getPayload() {
return null;
}
@Override
public ConstraintTarget getValidationAppliesTo() {
return null;
}
@Override
public List<Class<? extends ConstraintValidator<Annotation, ?>>> getConstraintValidatorClasses() {
return null;
}
@Override
public Map<String, Object> getAttributes() {
return null;
}
@Override
public Set<ConstraintDescriptor<?>> getComposingConstraints() {
return null;
}
@Override
public boolean isReportAsSingleViolation() {
return false;
}
@Override
public ValidateUnwrappedValue getValueUnwrapping() {
return null;
}
@Override
public <U> U unwrap(Class<U> type) {
return null;
}
};
}
示例12: setPayload
import javax.validation.Payload; //导入依赖的package包/类
public Builder<T> setPayload(final Class<? extends Payload>[] classes) {
this.setPayload(new HashSet<>(Arrays.asList(classes)));
return this;
}
示例13: getPayload
import javax.validation.Payload; //导入依赖的package包/类
@Override
public Set<Class<? extends Payload>> getPayload() {
return this.payload;
}
示例14: getPayload
import javax.validation.Payload; //导入依赖的package包/类
@Override
public Set<Class<? extends Payload>> getPayload() {
return Collections.emptySet();
}
示例15: payload
import javax.validation.Payload; //导入依赖的package包/类
Class<? extends Payload>[] payload() default {};
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:2,代码来源:RelaxedDataBinderTests.java