Open topic with navigation

TIBCO® Enterprise Administrator 2.4.2

# Using POJOs in Python Scripts

This procedure uses an example of the Person class as the Java object that is used as a TeaParam to TeaOperation and return type of the TeaOperation. POJOs can be used just as you use regular Python objects.

Procedure
1. Install the jsonpickle module. This module must be installed separately using pip. Refer the Python documentation for more details. You need the jsonpickle module to serialize and deserialize java objects. Based on the version of Python you are using, you can install the module using the following command:

   Python Version | Command
   --- | ---
   2 | pip install jsonpickle
   3 | pip3 install jsonpickle

2. Define a POJO. The following example defines a Person class:

       package com.tibco.tea.agent;

       import com.fasterxml.jackson.annotation.JsonPropertyOrder;

       @JsonPropertyOrder({ "name", "i" })
       public class Person {

           private String name;

           private int i;

           public void setName(String name) {
               this.name = name;
           }

           public void setI(int i) {
               this.i = i;
           }

           public String getName() {
               return this.name;
           }

           public int getI() {
               return this.i;
           }

       }

3. Define a TeaOperation that takes a POJO as TeaParam and returns a POJO.

       @TeaOperation(name = "hw", description = "Send greetings")
       public Person helloworld(
               @TeaParam(name = "greetings", description = "Greetings parameter") final Person greetings) throws IOException {
           return greetings;
       }

4. Invoke the TeaOperation as follows:

       # Import the tibco.tea module and make the connection
        to the TEA Server
       >>> import tibco.tea
       >>> tea = tibco.tea.EnterpriseAdministrator()

       # First get hold of the product or member of the TeaOperation
        you want to invoke
       >>> prod = tea.product_with_provisional_api('HelloWorldTopLevelType')

       # Module of POJOs is available on that product or member in
       variable "module_"
       >>> mod = prod.module_

       # Now instantiate the POJO class in python as follows
       >>> person = mod.Person("John Doe", 1)

       # Invoke the TeaOperation with the python object in the earlier line
        as TeaParam and consume the POJO response as a Python Object
       >>> response = prod.hw(person)

       # Use the response as you use the normal python object
       >>> response.name
       'John Doe'
       >>> response.i
       1

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Enterprise Administrator

Copyright © 1996-2025. Cloud Software Group, Inc. All Rights Reserved.