I imported a project that use lombok to decrease code, but I got error "The method getBooks() is undefined for the type Author", where Book and Author are two entities.
this.getBooks().add(book);
book.setAuthor(this);
The Book Class used such anootations, and I also got warning "The type Builder is deprecated", how can I solve this problems?
#Entity
#Data
#Builder
#AllArgsConstructor
#NoArgsConstructor
#EqualsAndHashCode(exclude = "id")
#ApiObject(name = "Book", group = DocumentationConstants.GROUP_LIBRARY, description = "Represents a book. Every book has an <code>Author</code> and a price.")
public class Book {
...
}
I don't know about the problem regarding getBooks, but to solve the deprecation warning, you probably should replace the import from lombok.experimental.Builder to lombok.Builder
Disclosure: I am a Lombok developer.
Related
Below is my Feature File
Scenario Outline: CucumberTest
Given Generate Data Set
"""json
{
"tcIdentifier":"TC1"
}
"""
Examples:
|TESTCASEIDENTIFIER|
|TC1 |
Step Defintion Would Look Like Below
#Given("Generate Data Set")
public void generateDataSet(DataSetMetaData dataSetMetaData) {
System.out.println(dataSetMetaData);
}
#DocStringType
public DataSetMetaData createTestDataForSorting(String details) throws JsonProcessingException {
return new ObjectMapper().readValue(details, DataSetMetaData.class);
}
Details of the DataSetMetaData
#Getter
#Setter
#ToString
#AllArgsConstructor
#Builder
#NoArgsConstructor
public class DataSetMetaData {
private String tcIdentifier;
}
Expected : Data Binding from the Docstring to be Transformed to DataSetMetaData POJO
ACtual : We Are Encountered with the Exception
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "tcIdentifier" not marked as ignorable (0 known properties: ])
From Some of the Previous Responses on similar - Exception - community has suggested to Annotate the Field as #JsonProperty - What I am Failing to Understand - if the variable Names matches the JSON Data Key - Ideally Binding Should work - For some Strange Reason - even if the attribute Exist - UnrecognizedPropertyException: Unrecognized field "tcIdentifier"
Following are the maven Co-ordinates related to the Cucumber and Jackson Dependencies
implementation group: 'io.cucumber', name: 'cucumber-java', version: '7.3.4
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.2'
Do let me know if any Further Information is required
#M.P. Korstanje and #GaƫlJ - Thank you very much for insights and giving directions towards analysis in the right Direction
Adding the Lombok Dependencies with the scope of annotationProcessor did the magic - Hope it Helps
I am developing my Eclipse Plugin using E4 2020-09 version. I created a Perspective and a menuContribution using Model Fragments. I have searched several tutorials but I have not seen any that showing how to make a menuContribution appear/disappear when opening/closing a Perspective in E4 during development. What I found was these examples: https://github.com/vogellacompany/codeexamples-eclipse but this function is implemented for E3 and I want to implement it in E4.
Can you give me some hints/advices about this technique and how it is called or where to start with it?
Thanks and best regards.
You can do this in the 'Visible-When Expression' for the menu items.
Set the expression to be 'ImperativeExpression'. And create a class to handle the expression. This class just has a single method annotated with #Evaluate which is called each time the menu item might be displayed:
#Evaluate
public boolean evaluate(EModelService modelService, .... other parameters)
{
// TODO determine if menu item should be visible
}
This class can then use the getActivePerspective method of EModelService to check if the menu item should be visible.
449,
Thank you for you answer, I finally made it according to your instruction. I will leave my reference code here in case there are people asking about this:
Create MenuContributionsHandler class
package com.catto.ide.dev.handlers;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Evaluate;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
public class MenuContributionsHandler
{
#Inject MWindow window;
#Evaluate
public boolean evaluate(EModelService modelService)
{
// TODO determine if menu item should be visible (return true)
MPerspective currentPerspective = modelService.getActivePerspective(window);
if (null != currentPerspective)
{
return currentPerspective.getLabel().equals("SnowCatto");
}
return false;
}
}
Add this class to the Imperative Expression to MenuContribution Class URI.
Best regards.
I'm having some trouble getting typing to work with the JsonSlurper in Groovy. I'm fairly new to Groovy, and even newer to adding strong types to it - bear with me.
Right now I've created a trait which defines the general shape of my JSON object, and I'm trying to cast the results of parseText to it.
import groovy.json.JsonSlurper
trait Person {
String firstname
String lastname
}
def person = (Person)(new JsonSlurper().parseText('{"firstname": "Lando", "lastname": "Calrissian"}'))
println person.lastname
This throws
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{firstname=Lando, lastname=Calrissian}' with class 'org.apache.groovy.json.internal.LazyMap' to class 'Person' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Person(org.apache.groovy.json.internal.LazyMap)
...
I can see why my code doesn't make sense, I'm not trying to change the type of the data (casting), I'm just trying to let my IDE know that this is what's inside of my object.
Is it possible to at least add code completion to my JSON objects? I'd love to get runtime type checking, as well, but it's not necessary.
you could try to use delegate
this allows to wrap class around map
import groovy.json.JsonSlurper
class Person {
#Delegate Map delegate
String getFirstname(){ delegate.get('firstname') }
String getLastname(){ delegate.get('lastname') }
}
def person = new Person(delegate:new JsonSlurper().parseText('{"firstname": "Lando", "lastname": "Calrissian"}'))
println person.lastname
or for example use Gson for parsing:
#Grab(group='com.google.code.gson', module='gson', version='2.8.5')
import com.google.gson.Gson
class Person {
String firstname
String lastname
}
def person = new Gson().fromJson('{"firstname": "Lando", "lastname": "Calrissian"}', Person.class)
assert person instanceof Person
println person.lastname
This actually is a cast and Groovy will try to turn your Map into said object.
From the docs:
The coercion operator (as) is a variant of casting. Coercion converts object from one type to another without them being compatible for assignment.
The way this works for a POJO is to construct a new object using the Map-c'tor. This will either unroll into calling setters or works directly with static compilation.
Be aware, that using maps with excess keys will lead to errors. So I'd only use this for toy projects. Use a proper JSON-mapper like e.g. Jackson instead.
So the solution here is to not use a trait (which is basically a interface) but a regular class.
When I've created an ActorComponent c++ subclass with TSubclassOf UPROPERTY and set this class in blueprint I can't read read this property in c++ constructor.
In .h file I've got this:
protected:
UPROPERTY(EditAnywhere, Category = "Setup")
TSubclassOf<UBaseSkill> PrimarySkillClass;
And this in .cpp:
USkillSet::USkillSet()
{
if(PrimarySkillClass.Get())
{
UE_LOG(LogTemp, Warning, TEXT("Creating skill"));
}
else
{
UE_LOG(LogTemp, Error, TEXT("No skill class"));
}
}
In BP I'm setting a class:
BP screenshot
so PrimarySkillClass.Get() should return true, but I'm getting "No skill class" in log. Why and how could I fix this?
The constructor is the first method ever called on an object, it's to early on the life of the UObject. Properties, values from Blueprints and components are initialized afterwards.
So you have to access them later, either on UObject::PostInitProperties() or on BeginPlay() if it's not too late for your purpose.
Edit: interesting reading on UObject Constructor, PostInitProperties and PostLoad
Can anyone please share the steps to setup GORM using gradle and use the same in groovy ?
GORM for Hibernate has excellent documentation
Particularly the section of Using GORM For Hibernate Outside Grails
At minimum you need:
compile "org.grails:grails-datastore-gorm-hibernate5:6.1.10.RELEASE"
runtime "com.h2database:h2:1.4.192"
runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"
runtime "org.slf4j:slf4j-api:1.7.10"
Entities should go under src/main/groovy
#Entity
class Person implements GormEntity<Person> {
String firstName
String lastName
static constraints = {
firstName blank:false
lastName blank:false
}
}
and then finally bootstrap the data store somewhere:
import org.grails.orm.hibernate.HibernateDatastore
Map configuration = [
'hibernate.hbm2ddl.auto':'create-drop',
'dataSource.url':'jdbc:h2:mem:myDB'
]
HibernateDatastore datastore = new HibernateDatastore( configuration, Person)