facebookarchive / swift

An annotation-based Java library for creating Thrift serializable types and services.
Apache License 2.0
900 stars 297 forks source link

Need method to add 3rd party types to catalog for swift2thrift #237

Closed allComputableThings closed 6 years ago

allComputableThings commented 9 years ago

I'd like make it easy to taken existing service interfaces (dealing with some third party beans types), and make them available as a swift service and generate thrift clients via swift2thrift.

A number of serialization frameworks provide the ability to serialize types without adding requiring ownership of the source code for that types (e.g. Jackson support serialization of beans) -- so, I'm working on a method to register types prior to:

I'm looking at providing an alternate SwiftStructMetaDataBuilder to do this. It will:

Does this look the reasonable approach (adding a SwiftStructMetaDataBuilder, using it to generate a ThriftType and registering the type with the catalog)?

allComputableThings commented 9 years ago

Or is there some feature that does this already?

allComputableThings commented 9 years ago

I'm part way through builder an StructMetaDatabuilder for unannotated Java and scala types. I have some questions about StructMetaDatabuilder. Given:

@ThriftStruct
final public class JavaBean {
    public JavaBean() {}

    private String street =  "";

    @ThriftField(1)
    public String getStreet() { return street; } 

    @ThriftField
    public void setStreet(String street) { this.street=street; }    
}

then StructMetaDatabuilder yields:

ThriftStructMetadata{
structName='JavaBean', 
structType=class net.ailive.JavaBean, 
builderType=null, 
builderMethod=Optional.absent(), 
fields={
   1=ThriftFieldMetadata{
     id=1, 
     thriftType=ThriftType{STRING class java.lang.String}, 
     name='street', fieldKind=THRIFT_FIELD, 
     injections=[ThriftParameterInjection{fieldId=1, name=street, index=0, javaType=class java.lang.String}], 
     constructorInjection=Optional.absent(), 
     methodInjection=Optional.absent(), 
     extraction=Optional.of(ThriftMethodExtractor{id=1, name='street', fieldKind=THRIFT_FIELD, method=public java.lang.String net.ailive.JavaBean.getStreet(), type=class java.lang.String}), 
     coercion=Optional.absent()}}, 
constructorInjection=Optional.of(net.ailive.JavaBean()), 
methodInjections=[setStreet(ThriftParameterInjection{fieldId=1, name=street, index=0, javaType=class java.lang.String})]}
  1. Why aren't the injectors and extractors treated symmetrically?
    • ThriftFieldMetadata has an extraction that specifies the JavaBean.getStreet. But the corresponding injector is absent (and is instead stored as a ThriftFieldMetadata attribute).
  2. Why are injectors lists, but the extractors single attributes?
  3. What does the constructorInjection refer to in the ThriftFieldMetadata?
  4. What do the various coercions effect?
  5. What do the optional builders effect?

(not trying to criticize, just trying to understand what's what).

ghost commented 9 years ago

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.