Questions tagged [java-annotations]

211 questions
9
votes
1 answer

About the parameter defined in process(...) method of Processor interface

In javax.annotation.processing package there is a interface Processor in which there is a function: /** * Processes a set of annotation types on type elements * originating from the prior round and returns whether or not * these…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
8
votes
2 answers

POJOs generated by jsonschema2pojo have annotation which Android Studio doesn't understand

When I generate POJOs via http://www.jsonschema2pojo.org/ I get something like this: import javax.annotation.Generated; import com.google.gson.annotations.Expose; import…
Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
7
votes
2 answers

Why does JPMS allow annotation types as services

In introducing JPMS services, section 7.7.4 of the Java Language Specification notes that "The service type must be a class type, an interface type, or an annotation type." I'm struggling to see the point of permitting an annotation. My…
Toby Eggitt
  • 1,806
  • 19
  • 24
6
votes
2 answers

What's is the difference between a static and non-static annotation?

Java's inner classes can be static or non-static. Non-static inner classes are tied to an instance of the enclosing class. Annotations are a type of Java interface, and like any other class, they can be defined inside a class. Similarly, they can be…
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
5
votes
0 answers

How add method to java class using custom annotation

I want to create a java annotation which generates a method in compile-time, like Lombok for example: I have this class : @MyNewAnnotation() public class ClassTest { private String name; private Integer id; private String lastName; …
roberto
  • 163
  • 1
  • 11
5
votes
1 answer

Dozer, how to ignore a field with annotation

I'm using dozer to map objects. How can I ignore (exclude) a field using annotations with dozer? Something like: class A { @IgnoreField public String someField; } class B { public String someField; } …
satellite satellite
  • 893
  • 2
  • 10
  • 27
5
votes
1 answer

Android Studio can't find javax.annotation.processing.AbstractProcessor

I want to learn Annotation, and i create a demo project. But when I create a class extends AbstractProcessor, Android Studio can't find this class. How can I add it.
Charon Chui
  • 71
  • 2
  • 8
4
votes
0 answers

Can I get source line number when processing annotations in Java?

In the process of writing a Java program doing a lot of logging using java.util.logging (keeping it simple) I was wondering if I could generate the (MyJavaFile.java:123) bit with the java annotation processor at compile time creating static strings…
4
votes
1 answer

@Transactional needs to rollback everything except one save in database

I have a method: @Transactional @Override public void createFile(final String number) { try { //code to save values throw new Exception(number); } catch(Exception e){ …
4
votes
1 answer

Use UUID in annotation interface as default value

is possible to use UUID in annotation attribute? I tried add UUID in annotation as attribute as you can see below but it gives me error Attribute value must be constant. @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { …
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
4
votes
1 answer

Is there a way to have method annotations passed on to sub-classes?

I have a few custom method annotations used on methods which are typically overridden. For example, let's consider something like an @Async annotation: public class Base { @Async public void foo() { } } Is there a way to signal to the…
JHH
  • 8,567
  • 8
  • 47
  • 91
4
votes
1 answer

Get Class fields from annotated Object in annotation processor

i'm working on my first annotation processor. I'm trying to get fields of class through annotation on declared object(that is a field of a method). For example: public class Person { private String name; private String…
4
votes
1 answer

Foreign key references primary key in spring boot

I working on adding MCQ question, options and Answer. There are three tables Question, Option and Answer. Below is my database schema questionId (Question table) is primary key referred to by questionId (Option table) is foreign key. questionId…
4
votes
1 answer

How to make an annotaion that calls other annotations

I usually use specific lombok and spring annotations in every class that I open in work. Is there a way that I can create my custom annotation that will call the annotations that I need? This is my class for…
Daniel A.
  • 76
  • 6
4
votes
1 answer

Create custom annotation that uses @JsonIgnore based on value in environment variable in Java

I need to create a new annotation which is used to ignore a field in the output JSON file when the environment variable var == false. I tried to use JsonAnnotationIntrospector, but could not get the expected output. public class Vehicle { String…
1
2
3
14 15