Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json deserialization #910

Closed
hlehmann opened this issue Dec 1, 2018 · 5 comments
Closed

Json deserialization #910

hlehmann opened this issue Dec 1, 2018 · 5 comments
Labels
enhancement Improved functionality

Comments

@hlehmann
Copy link

hlehmann commented Dec 1, 2018

In order to easily use the json file for documentation rendering, could it be possible to "deserialize" and get a ProjectReflection object ?

@Gerrit0 Gerrit0 added the enhancement Improved functionality label Dec 1, 2018
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 1, 2018

Neat idea! Currently not possible, and this would probably require a fair bit of work since serialization is spread out over so many different classes right now. If you want a ProjectReflection for now it's probably best to use the api to generate one.

const td = require('typedoc');
const app = new td.Application({
  // options
});
const inputFiles = app.expandInputFiles('src');
const projectReflection = app.convert(inputFiles);

@mootari
Copy link

mootari commented Dec 14, 2018

From what I (believe to) recall this is practically impossible at the moment because:

  • not all the required information is retained in the JSON output,
  • there's a lot of cross-references between reflections that cannot be restored,
  • there are references to TypeScript type instances that cannot be skipped.

A better way might be to stop accessing reflection instances in the theme and instead rely on a reduced dataset (like from toObject()).

@Gerrit0 Gerrit0 added the wontfix Declining to implement label May 11, 2019
@Gerrit0
Copy link
Collaborator

Gerrit0 commented May 11, 2019

I recently spent quite a bit of time in the serialization code and agree with mootari. There isn't any nice way to resolve this. If you need a ProjectReflection when rendering a theme, the best way to do that is to use the code I provided above.

@Gerrit0 Gerrit0 closed this as completed May 11, 2019
@Gerrit0 Gerrit0 removed the wontfix Declining to implement label May 23, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented May 23, 2020

So... this seems to be a recurring theme with TypeDoc for me. I think something is impossible, then 6 months or a year later I come back and realize - this isn't that difficult. There are a few things that need to happen first (and some of these are being done for library mode), but this is definitely doable, and I really like the idea.

  • Semi-revert the serialization work done to separate models and serailizers. We still need the serialization module so that plugins can add their own data to the serialized models, but much of it can be restored to the models so that the code lives together and is easier to reason about.
  • Create a new method on Application:
    interface Application {
        restoreFromJson(json: object): ProjectReflection
    }
  • Create the Deserializer module.
    interface Deserailizer {
        addReflectionDeserailizer(kind: ReflectionKind, Extract<SomeReflection, { kind }>)
        addTypeDeserailizer(kind: TypeKind, Extract<SomeType, { kind }>)
        deserializeReflection(json: object): SomeReflection
        deserializeType(json: object): SomeType
    }

The deserializer should work in much the same way as the serializer used in library mode (not pushed to GH yet, still have another 200 or so type errors to fix...)

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 2, 2022

#1180 is the more common user facing side of this feature, so I'm going to track it over there.

@Gerrit0 Gerrit0 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

3 participants