Optimal approach to configuring Spring Boot and Angular for seamless communication with Facebook Marketing API

Currently, I am working on a Spring Boot backend application and incorporating the Facebook marketing SDK. For the frontend, I am utilizing Angular 10. Whenever I create a new page or campaign, my goal is to send the corresponding object back to the frontend application with all the required properties of the campaign.

I attempted to use the typescript-generator tool from Habarta, but encountered challenges due to the complexity of the Facebook Java classes, resulting in conflicting outcomes during the generation process. An example of this issue is:

When parsing 'com.facebook.ads.sdk.ProductFeedRuleSuggestion' for 'APIRequestGetSuggestedRules.lastResponse'
Warning: Several classes are associated with 'APIRequestGetActivities'. Conflicting classes: [class com.facebook.ads.sdk.AdAccount$APIRequestGetActivities, class com.facebook.ads.sdk.AdSet$APIRequestGetActivities]
...
[ERROR] The execution of goal cz.habarta.typescript-generator:typescript-generator-maven-plugin:2.25.695:generate (default-cli) failed while processing 'simplephy' project: The default-cli execution of cz.habarta.typescript-generator:typescript-generator-maven-plugin:2.25.695:generate was unsuccessful due to having multiple classes mapped with the same name. To resolve conflicts or exclude unintended classes, consider using 'customTypeNaming' or 'customTypeNamingFunction' settings.

Here is how my plugin is set up:

<plugin>
    <groupId>cz.habarta.typescript-generator</groupId>
    <artifactId>typescript-generator-maven-plugin</artifactId>
    <version>2.25.695</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
    <configuration>
        <jsonLibrary>jackson2</jsonLibrary>
        <mapClasses>asClasses</mapClasses>
        <classes>
             <class>com.facebook.ads.sdk.Campaign</class>
        </classes>
        <excludeClasses>
            <excludeClass>com.facebook.ads.sdk.APINode</excludeClass>
        </excludeClasses>
        <outputKind>module</outputKind>
        <outputFileType>implementationFile</outputFileType>
    </configuration>
</plugin>

What would be the most effective approach to generating the essential TypeScript classes based on the Facebook Java objects? Alternatively, are there better methods for transferring these Facebook objects between the backend and frontend applications?

Answer №1

To properly handle naming conventions, it is crucial to create a customTypeNamingFunction like the following:

<customTypeNamingFunction>
    function(name, simpleName) {
        <!-- RENAMING DUPLICATES -->
        var duplicates = ['class', 'names', 'duplicated'];

        if (name.indexOf('$') !== -1) {
            var parent = name.split('$')[0];
            var parentParts = parent.split('.');
            return parentParts[parentParts.length-1]+simpleName;
        } 
        if (duplicates.indexOf(simpleName) !== -1) {
            var parts = name.split('.');
            var caps = parts[parts.length-2][0].toUpperCase() + parts[parts.length-2].slice(1);
            return caps+parts[parts.length-1];
        } 
    }
</customTypeNamingFunction>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing JavaScript's Array.sort() method for sorting objects with varying properties

Currently, I am dealing with these specific Objects: let obj1 = { from: Date, to: Date } let obj2 = { date: Date } These Objects have been placed in an Array: let arr = [ obj1, obj2 ] My goal is to organize the objects within the array by using arr.sort( ...

In Java, a superclass array object is being assigned with a subclass array object

I am facing an issue where I am trying to assign an array of sub class objects to an array of super class objects in Java. The program compiles without errors, but I am getting an ArrayStoreException at runtime. I understand that both arrays 'parent&a ...

Unable to locate the JSON object (utilizing org.json library)

Microsoft Academic has developed an API for retrieving general information from Microsoft academic. The response format is a Json Object. Attempting to read the response object using org.Json and the code below, unsuccessful results were encountered (requi ...

What sets apart exporting a component from importing its module in another module?

When working with Angular, consider having both module A and module B. If I intend to utilize "A-component" within components of module B, what is the distinction between importing module A in Module B compared to including the "A-component" in the exports ...

Utilizing TypeScript to export a class constructor as a named function

Imagine you have this custom class: export class PerformActionClass<TEntity> { constructor(entity: TEntity) { } } You can use it in your code like this: new PerformActionClass<Person>(myPersonObject); However, you may want a more co ...

How can I subtract a value from my array in Angular?

I've been troubleshooting this problem for a while now and I'm hoping that someone here can assist me with finding a solution. The issue at hand involves an array object containing various values such as id, title, amountCounter. Specifically, t ...

Error when the class is not found + Application

I am attempting to create my debut Applet named MemoSaver2.java In addition, I have crafted the following html: <html> <object classid="java:MemoSaver2.class" type="application/x-java-applet" archive="MemoSaver2.jar" he ...

The data type 'string' cannot be assigned to the data type 'Position'

Currently, I am in the process of converting React js to typescript. The component being used is a Class Component. I would like to obtain CSS settings through props and apply them to an element. How can I resolve this issue? render(){return( <span st ...

Selenium tests using TestNG are failing to run simultaneously

I have configured my TestNG settings to allow parallel execution of Selenium tests: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Test-Automation" parallel="methods" thread-c ...

Encountering an issue while trying to import the validator module in NextJS 13

I encountered a peculiar issue while trying to import a module. Nextjs presented the following error message: ./application/sign_in/sign_in_store.ts:2:0 Module not found: Can't resolve 'validator' 1 | import { createEvent, createStore } fr ...

Converting Intel hex strings to regular hex format using Java

Seeking assistance with converting a string from Intel Hex format to hexadecimal and then to decimal. The data originates from a GPS device. The desired outcome is as follows: Intel hex : 85630800 (input) device hex : 00086385 decimal : 549765 An ...

Incorporating jsbi into a TypeScript project while adhering to strict mode

I have been developing a TypeScript library that relies on native BigInts. While it functions perfectly in Chrome, I encountered some issues with Safari. After some research, I stumbled upon the jsbi "polyfill" that seems to solve this problem. Unfortunat ...

Positioning a Box tag at the bottom using MUI 5

My goal is to position a Box tag at the bottom of the page. Current Behavior: https://i.stack.imgur.com/ZupNo.png I am looking to place a TextField and send button at the bottom of the page on both browser and mobile. I want user messages to be above th ...

What could be the reason for the defaultCommandTimeout not functioning as expected in my script

Is there a way to wait for only one particular element in Cypress without having to add wait commands everywhere in the test framework? I've come across the solution of adding defaultCommandTimeout in the cypress.json file, but I don't want it t ...

What is the best way to verify if an object is an instance of a particular class using Jasmine testing?

In the process of developing an Angular application, I am currently working on testing a component using this guide. My goal is to ensure that when my ngOnInit() method is called, it correctly initializes my foos property with an array of Foo objects based ...

Passing a message from a Struts2 action to jQuery

When using jQuery Ajax to call a Struts2 action, I have the following setup: $.ajax ({ url: 'callAction.action', type: 'POST', data: data, dataType: 'string', success: function (data ...

What is the best way to exchange data between Swing components in Java?

I have a Swing application that is responsible for conducting various calculations, creating graphs, generating reports, and more. Within one JFrame, data is inputted via a JTable, calculations are carried out, and a Map containing the information is ret ...

Testing Angular applications using Karma

After utilizing the yo angular 1 generator, it generated a landing page and some tests. However, I am facing an issue when trying to compile the code in VS as I receive an error stating that "module('fountainFooter');" is undefined. /// <refe ...

Could someone provide an explanation for the meaning of the phrase "class User extends Model<UserAttribute UserCreationAttribute>"?

View Image of the Issue I am puzzled by why we are utilizing both UserCreationAttribute and UserAttribute in that specific arrow, especially when UserCreationAttribute is created by omitting one field from UserAttribute. Can someone please clarify this fo ...

Jackson is a powerful tool in JAVA that allows you to easily parse string and convert it to JSON. Here

I'm currently attempting to transform a string into JSON using Jackson. To achieve this, I've utilized the ObjectMapper().readValue() method to deserialize it into a DragDropJsonDto object. The structure of qList.getHeader() is as follows: &quo ...