annotations

Non-void test methods in JUnit 4

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-06 13:51:06
问题 I would like a JUnit 4 test class to implement the same interface as the class its testing. This way, as the interface changes (and it will, we're in early development), the compiler guarantees that corresponding methods are added to the test class. For example: public interface Service { public String getFoo(); public String getBar(); } public class ServiceImpl implements Service { @Override public String getFoo() { return "FOO"; } @Override public String getBar() { return "BAR"; } } public

How to parse a json field that may be a string and may be an array with Jackson

微笑、不失礼 提交于 2021-02-05 06:49:05
问题 I have a json field that is string when there's one value: { "theField":"oneValue" } or array when there are multiple values: { "theField": [ "firstValue", "secondValue" ] } And then I have my java class that uses com.fasterxml.jackson.annotation.JsonCreator: public class TheClass { private final List<String> theField; @JsonCreator public TheClass(@JsonProperty("theField") List<String> theField) { this.theField = theField; } } The problem is that the code does not work when the incoming field

Are annotations on a type parameter accessible in runtime?

时光毁灭记忆、已成空白 提交于 2021-02-04 14:10:42
问题 Java 8 allows things like: public List<@NonNull String> names; But is there a way to access this annotation in runtime or is it available only to compiler plugins? There's new Method#getAnnotatedReturnType that provides access to annotations on the return type, so I was hoping ParameterizedType would now have something like getActualAnnotatedTypeArguments that would do the same for generic type arguments, but it doesn't exist... 回答1: The new API continues the tradition of requiring lots of

How to prevent Spring validation on update

荒凉一梦 提交于 2021-02-04 07:15:12
问题 I made a custom validation annotation for unique email (When user registers itself, program checks if email is already in database). Everything works just fine, but when I need to modify user's info and not to create a new one I run into a problem that says "Email is already in use" Can I somehow turn off only @UniqueEmail validation(I need the others like email pattern and password validation)? All validation annotations are in the same User bean. Thank You. 回答1: I'm going to assume that you

How we can use spring AOP custom annotation in Other Spring Boot project

一个人想着一个人 提交于 2021-01-29 19:52:08
问题 I am new in Spring AOP, Here I have created one spring annotation for logger purpose Which I want to use in Different spring boot project. Since In same project I am able to print log messages but It's not working for different project. Please see below pom.xml file. SpringAOp project pom.xml file <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

Scala read method annotations from another project

旧城冷巷雨未停 提交于 2021-01-29 16:14:53
问题 I have a sbt config with scala play! server, a scalajs client, and shared project which contains classes which are passed between the two. I want my client to have strong type information for the server API calls so I'm writing a task that for each route in the routes file builds a corresponding method in the client. I have a prototype that is able to parse almost all of the information I need out of the routes file. The only thing I can't get is return types. Here's what I have so far (I

How can I reflect on a field annotation (Java) in a Scala program?

浪子不回头ぞ 提交于 2021-01-29 14:21:35
问题 I'm using Scala 2.13 and I know there's been a lot deprecated since older versions. I've got this annotation: @Inherited @Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface Foo { int index() default 0; } (I know... I've got lots of ElementTypes there, but I'm struggling to see where this pops up in reflection so wanted to maximize my chances of a hit!) Used like this: case class Person(name: String, @Foo(index = 3) age:

How to map errorType using Micronaut client annotation

断了今生、忘了曾经 提交于 2021-01-29 13:02:22
问题 How to map errorType using Micronaut client annotation, In case of programatically we can provide body type and errorType objects in case of success and failure. Programmatically calling client: import io.micronaut.core.type.Argument; import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpResponse; import io.micronaut.http.MediaType; import io.micronaut.http.client.DefaultHttpClient; import io.micronaut.http.client.exceptions.HttpClientResponseException; import io.micronaut.http

Typing a decorator that curries functions

大憨熊 提交于 2021-01-29 12:29:18
问题 I came across this interesting snippet on GitHub that curries functions and decided to try to add annotations. So far I have the following. from typing import cast, Callable, TypeVar, Any, Union from functools import wraps U = TypeVar('U') def curry(f: Callable[..., U]) -> Callable[..., U]: @wraps(f) def curry_f(*args: Any, **kwargs: Any) -> Union[Callable[..., U], U]: if len(args) + len(kwargs) >= f.__code__.co_argcount: return f(*args, **kwargs) # do I need another @wraps(f) here if curry_f

How to map errorType using Micronaut client annotation

一个人想着一个人 提交于 2021-01-29 12:18:45
问题 How to map errorType using Micronaut client annotation, In case of programatically we can provide body type and errorType objects in case of success and failure. Programmatically calling client: import io.micronaut.core.type.Argument; import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpResponse; import io.micronaut.http.MediaType; import io.micronaut.http.client.DefaultHttpClient; import io.micronaut.http.client.exceptions.HttpClientResponseException; import io.micronaut.http